From 2a219a994869ebf6012371d4188f23bbdebd3bcf Mon Sep 17 00:00:00 2001 From: Reijhanniel Jearl Campos Date: Thu, 5 Feb 2015 21:45:03 +0800 Subject: [PATCH] JCLOUDS-702: JClouds ProfitBricks provider - Storage API --- .../jclouds/profitbricks/ProfitBricksApi.java | 4 + .../profitbricks/ProfitBricksApiMetadata.java | 30 +- .../ProfitBricksProviderMetadata.java | 18 +- .../binder/BaseProfitBricksRequestBinder.java | 6 +- .../CreateDataCenterRequestBinder.java | 10 +- .../server/CreateServerRequestBinder.java | 46 +-- .../server/UpdateServerRequestBinder.java | 42 +-- .../ConnectStorageToServerRequestBinder.java | 45 +++ .../storage/CreateStorageRequestBinder.java | 46 +++ .../storage/UpdateStorageRequestBinder.java | 47 +++ .../internal/ProvisioningStatusAware.java | 2 +- .../ProvisioningStatusPollingPredicate.java | 9 +- .../config/ProfitBricksHttpApiModule.java | 8 +- .../profitbricks/domain/AvailabilityZone.java | 6 +- .../profitbricks/domain/DataCenter.java | 94 +++-- .../jclouds/profitbricks/domain/Location.java | 8 +- .../domain/ProvisioningState.java | 4 +- .../jclouds/profitbricks/domain/Server.java | 160 ++++---- .../profitbricks/domain/ServiceFault.java | 28 +- .../jclouds/profitbricks/domain/Storage.java | 355 ++++++++++++++++++ .../profitbricks/features/DataCenterApi.java | 12 +- .../profitbricks/features/ServerApi.java | 74 ++-- .../profitbricks/features/StorageApi.java | 136 +++++++ .../ProfitBricksHttpErrorHandler.java | 53 +-- ...FromPayloadHttpCommandExecutorService.java | 92 +++-- .../ProfitBricksSoapMessageEnvelope.java | 6 +- .../BaseProfitBricksResponseHandler.java | 21 +- .../parser/RequestIdOnlyResponseHandler.java | 14 +- .../parser/ServiceFaultResponseHandler.java | 19 +- .../BaseDataCenterResponseHandler.java | 11 +- .../DataCenterInfoResponseHandler.java | 74 +++- .../DataCenterListResponseHandler.java | 16 +- .../image/BaseImageResponseHandler.java | 7 +- .../image/ImageInfoResponseHandler.java | 6 +- .../image/ImageListResponseHandler.java | 8 +- .../server/BaseServerResponseHandler.java | 85 +++-- .../server/ServerIdOnlyResponseHandler.java | 14 +- .../server/ServerInfoResponseHandler.java | 12 +- .../server/ServerListResponseHandler.java | 12 +- .../GetProvisioningStateResponseHandler.java | 9 +- .../storage/BaseStorageResponseHandler.java | 83 ++++ .../storage/StorageIdOnlyResponseHandler.java | 46 +++ .../storage/StorageInfoResponseHandler.java | 50 +++ .../storage/StorageListResponseHandler.java | 54 +++ .../BaseProfitBricksLiveTest.java | 4 +- .../CreateDataCenterRequestBinderTest.java | 12 +- .../UpdateDataCenterRequestBinderTest.java | 12 +- .../server/CreateServerRequestBinderTest.java | 46 +-- .../server/UpdateServerRequestBinderTest.java | 40 +- ...nnectStorageToServerRequestBinderTest.java | 55 +++ .../CreateStorageRequestBinderTest.java | 56 +++ .../UpdateStorageRequestBinderTest.java | 53 +++ ...rovisioningStatusPollingPredicateTest.java | 68 +++- .../domain/ServerBuilderTest.java | 190 +++++----- .../features/DataCenterApiMockTest.java | 19 +- .../features/ImageApiMockTest.java | 2 +- .../features/ServerApiLiveTest.java | 90 ++--- .../features/ServerApiMockTest.java | 209 ++++++----- .../features/StorageApiLiveTest.java | 167 ++++++++ .../features/StorageApiMockTest.java | 285 ++++++++++++++ ...PayloadHttpCommandExecutorServiceTest.java | 45 +++ .../ProfitBricksSoapMessageEnvelopeTest.java | 6 +- .../http/parser/BaseResponseHandlerTest.java | 4 +- .../RequestIdOnlyResponseHandlerTest.java | 24 +- .../ServiceFaultResponseHandlerTest.java | 10 +- .../DataCenterInfoResponseHandlerTest.java | 61 ++- .../DataCenterListResponseHandlerTest.java | 4 +- .../image/ImageInfoResponseHandlerTest.java | 44 +-- .../image/ImageListResponseHandlerTest.java | 248 ++++++------ .../ServerIdOnlyResponseHandlerTest.java | 8 +- .../server/ServerInfoResponseHandlerTest.java | 55 +-- .../server/ServerListResponseHandlerTest.java | 80 ++-- ...tProvisioningStateResponseHandlerTest.java | 114 +++--- .../StorageIdOnlyResponseHandlerTest.java | 42 +++ .../StorageInfoResponseHandlerTest.java | 66 ++++ .../StorageListResponseHandlerTest.java | 80 ++++ .../internal/BaseProfitBricksMockTest.java | 24 +- .../test/resources/datacenter/datacenter.xml | 2 +- .../src/test/resources/fault-404.xml | 2 +- .../src/test/resources/fault-413.xml | 17 + .../src/test/resources/maintenance-503.html | 67 ++++ .../server/server-state-inprocess.xml | 28 ++ .../resources/storage/storage-connect.xml | 13 + .../test/resources/storage/storage-create.xml | 14 + .../test/resources/storage/storage-delete.xml | 13 + .../resources/storage/storage-disconnect.xml | 13 + .../storage/storage-state-inprocess.xml | 23 ++ .../test/resources/storage/storage-update.xml | 13 + .../src/test/resources/storage/storage.xml | 23 ++ .../src/test/resources/storage/storages.xml | 37 ++ 90 files changed, 3278 insertions(+), 1092 deletions(-) create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinder.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinder.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinder.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Storage.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/StorageApi.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/BaseStorageResponseHandler.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandler.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandler.java create mode 100644 providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinderTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinderTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinderTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandlerTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandlerTest.java create mode 100644 providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandlerTest.java create mode 100644 providers/profitbricks/src/test/resources/fault-413.xml create mode 100644 providers/profitbricks/src/test/resources/maintenance-503.html create mode 100644 providers/profitbricks/src/test/resources/server/server-state-inprocess.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage-connect.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage-create.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage-delete.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage-disconnect.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage-state-inprocess.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage-update.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storage.xml create mode 100644 providers/profitbricks/src/test/resources/storage/storages.xml diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java index 7ab121a51a..4cfe6e8377 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java @@ -21,6 +21,7 @@ import java.io.Closeable; import org.jclouds.profitbricks.features.DataCenterApi; import org.jclouds.profitbricks.features.ImageApi; import org.jclouds.profitbricks.features.ServerApi; +import org.jclouds.profitbricks.features.StorageApi; import org.jclouds.rest.annotations.Delegate; public interface ProfitBricksApi extends Closeable { @@ -33,4 +34,7 @@ public interface ProfitBricksApi extends Closeable { @Delegate ServerApi serverApi(); + + @Delegate + StorageApi storageApi(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApiMetadata.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApiMetadata.java index f51dc5b377..205b246a82 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApiMetadata.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApiMetadata.java @@ -53,29 +53,29 @@ public class ProfitBricksApiMetadata extends BaseHttpApiMetadata { protected Builder() { - id("profitbricks") - .name("ProfitBricks API") - .identityName("API Username") - .credentialName("API Password") - .documentation(URI.create("https://www.profitbricks.com/sites/default/files/profitbricks_api_1_3.pdf")) - .defaultEndpoint("https://api.profitbricks.com/1.3") - .version("1.3") - // .view(ComputeServiceContext.class) - .defaultProperties(ProfitBricksApiMetadata.defaultProperties()) - .defaultModules(ImmutableSet.>of( - ProfitBricksHttpApiModule.class, - ProfitBricksHttpCommandExecutorServiceModule.class - )); + id("profitbricks") + .name("ProfitBricks API") + .identityName("API Username") + .credentialName("API Password") + .documentation(URI.create("https://www.profitbricks.com/sites/default/files/profitbricks_api_1_3.pdf")) + .defaultEndpoint("https://api.profitbricks.com/1.3") + .version("1.3") + // .view(ComputeServiceContext.class) + .defaultProperties(ProfitBricksApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.>of( + ProfitBricksHttpApiModule.class, + ProfitBricksHttpCommandExecutorServiceModule.class + )); } @Override public ProfitBricksApiMetadata build() { - return new ProfitBricksApiMetadata(this); + return new ProfitBricksApiMetadata(this); } @Override protected Builder self() { - return this; + return this; } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksProviderMetadata.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksProviderMetadata.java index d66ed15d32..9ecfbc1a0e 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksProviderMetadata.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksProviderMetadata.java @@ -44,23 +44,23 @@ public class ProfitBricksProviderMetadata extends BaseProviderMetadata { public static class Builder extends BaseProviderMetadata.Builder { protected Builder() { - id("profitbricks") - .name("ProfitBricks Cloud Compute 2.0") - .homepage(URI.create("http://www.profitbricks.com")) - .console(URI.create("https://my.profitbricks.com/dashboard/dcdr2/")) - .linkedServices("profitbricks") - .apiMetadata(new ProfitBricksApiMetadata()); + id("profitbricks") + .name("ProfitBricks Cloud Compute 2.0") + .homepage(URI.create("http://www.profitbricks.com")) + .console(URI.create("https://my.profitbricks.com/dashboard/dcdr2/")) + .linkedServices("profitbricks") + .apiMetadata(new ProfitBricksApiMetadata()); } @Override public ProfitBricksProviderMetadata build() { - return new ProfitBricksProviderMetadata(this); + return new ProfitBricksProviderMetadata(this); } @Override public Builder fromProviderMetadata(ProviderMetadata in) { - super.fromProviderMetadata(in); - return this; + super.fromProviderMetadata(in); + return this; } } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/BaseProfitBricksRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/BaseProfitBricksRequestBinder.java index 8c2d36b395..2b842fff43 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/BaseProfitBricksRequestBinder.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/BaseProfitBricksRequestBinder.java @@ -55,11 +55,11 @@ public abstract class BaseProfitBricksRequestBinder implements MapBinder { protected abstract String createPayload(T payload); - protected String formatIfNotEmpty(String pattern, Object param) { - return Strings.isNullOrEmpty(nullableToString( param )) ? "" : String.format(pattern, param); + protected static String formatIfNotEmpty(String pattern, Object param) { + return Strings.isNullOrEmpty(nullableToString(param)) ? "" : String.format(pattern, param); } - protected String nullableToString(Object object) { + protected static String nullableToString(Object object) { return object == null ? "" : object.toString(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/datacenter/CreateDataCenterRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/datacenter/CreateDataCenterRequestBinder.java index 8696c0ee7a..8a07b0aae7 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/datacenter/CreateDataCenterRequestBinder.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/datacenter/CreateDataCenterRequestBinder.java @@ -33,11 +33,11 @@ public class CreateDataCenterRequestBinder extends BaseProfitBricksRequestBinder @Override protected String createPayload(DataCenter.Request.CreatePayload payload) { requestBuilder.append("") - .append("") - .append(format("%s", payload.name())) - .append(format("%s", payload.location().value())) - .append("") - .append(""); + .append("") + .append(format("%s", payload.name())) + .append(format("%s", payload.location().value())) + .append("") + .append(""); return requestBuilder.toString(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinder.java index 4acf33b939..b836cebce9 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinder.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinder.java @@ -25,32 +25,32 @@ public class CreateServerRequestBinder extends BaseProfitBricksRequestBinder" ) - .append( "" ) - .append( format( "%s", payload.dataCenterId() ) ) - .append( format( "%s", payload.cores() ) ) - .append( format( "%s", payload.ram() ) ) - .append( formatIfNotEmpty( "%s", payload.name() ) ) - .append( formatIfNotEmpty( "%s", payload.bootFromStorageId() ) ) - .append( formatIfNotEmpty( "%s", payload.bootFromImageId() ) ) - .append( formatIfNotEmpty( "%s", payload.hasInternetAccess() ) ) - .append( formatIfNotEmpty( "%s", payload.lanId() ) ) - .append( formatIfNotEmpty( "%s", payload.osType() ) ) - .append( formatIfNotEmpty( "%s", payload.availabilityZone() ) ) - .append( formatIfNotEmpty( "%s", payload.isCpuHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isRamHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isNicHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isNicHotUnPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isDiscVirtioHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isDiscVirtioHotUnPlug() ) ) - .append( "" ) - .append( "" ); + protected String createPayload(Server.Request.CreatePayload payload) { + requestBuilder.append("") + .append("") + .append(format("%s", payload.dataCenterId())) + .append(format("%s", payload.cores())) + .append(format("%s", payload.ram())) + .append(formatIfNotEmpty("%s", payload.name())) + .append(formatIfNotEmpty("%s", payload.bootFromStorageId())) + .append(formatIfNotEmpty("%s", payload.bootFromImageId())) + .append(formatIfNotEmpty("%s", payload.hasInternetAccess())) + .append(formatIfNotEmpty("%s", payload.lanId())) + .append(formatIfNotEmpty("%s", payload.osType())) + .append(formatIfNotEmpty("%s", payload.availabilityZone())) + .append(formatIfNotEmpty("%s", payload.isCpuHotPlug())) + .append(formatIfNotEmpty("%s", payload.isRamHotPlug())) + .append(formatIfNotEmpty("%s", payload.isNicHotPlug())) + .append(formatIfNotEmpty("%s", payload.isNicHotUnPlug())) + .append(formatIfNotEmpty("%s", payload.isDiscVirtioHotPlug())) + .append(formatIfNotEmpty("%s", payload.isDiscVirtioHotUnPlug())) + .append("") + .append(""); return requestBuilder.toString(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinder.java index d051b88844..c12ae2154a 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinder.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinder.java @@ -25,31 +25,31 @@ public class UpdateServerRequestBinder extends BaseProfitBricksRequestBinder" ) - .append( "" ) - .append( format( "%s", payload.id() ) ) - .append( format( "%s", payload.cores() ) ) - .append( format( "%s", payload.ram() ) ) - .append( formatIfNotEmpty( "%s", payload.name() ) ) - .append( formatIfNotEmpty( "%s", payload.bootFromStorageId() ) ) - .append( formatIfNotEmpty( "%s", payload.bootFromImageId() ) ) - .append( formatIfNotEmpty( "%s", payload.osType() ) ) - .append( formatIfNotEmpty( "%s", payload.availabilityZone() ) ) - .append( formatIfNotEmpty( "%s", payload.isCpuHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isRamHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isNicHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isNicHotUnPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isDiscVirtioHotPlug() ) ) - .append( formatIfNotEmpty( "%s", payload.isDiscVirtioHotUnPlug() ) ) - .append( "" ) - .append( "" ); + protected String createPayload(Server.Request.UpdatePayload payload) { + requestBuilder.append("") + .append("") + .append(format("%s", payload.id())) + .append(format("%s", payload.cores())) + .append(format("%s", payload.ram())) + .append(formatIfNotEmpty("%s", payload.name())) + .append(formatIfNotEmpty("%s", payload.bootFromStorageId())) + .append(formatIfNotEmpty("%s", payload.bootFromImageId())) + .append(formatIfNotEmpty("%s", payload.osType())) + .append(formatIfNotEmpty("%s", payload.availabilityZone())) + .append(formatIfNotEmpty("%s", payload.isCpuHotPlug())) + .append(formatIfNotEmpty("%s", payload.isRamHotPlug())) + .append(formatIfNotEmpty("%s", payload.isNicHotPlug())) + .append(formatIfNotEmpty("%s", payload.isNicHotUnPlug())) + .append(formatIfNotEmpty("%s", payload.isDiscVirtioHotPlug())) + .append(formatIfNotEmpty("%s", payload.isDiscVirtioHotUnPlug())) + .append("") + .append(""); return requestBuilder.toString(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinder.java new file mode 100644 index 0000000000..2c2e08d65d --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinder.java @@ -0,0 +1,45 @@ +/* + * 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.profitbricks.binder.storage; + +import static java.lang.String.format; + +import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder; +import org.jclouds.profitbricks.domain.Storage; + +public class ConnectStorageToServerRequestBinder extends BaseProfitBricksRequestBinder { + + protected final StringBuilder requestBuilder; + + ConnectStorageToServerRequestBinder() { + super("storage"); + this.requestBuilder = new StringBuilder(128 * 2); + } + + @Override + protected String createPayload(Storage.Request.ConnectPayload payload) { + requestBuilder.append("") + .append("") + .append(format("%s", payload.storageId())) + .append(format("%s", payload.serverId())) + .append(formatIfNotEmpty("%s", payload.busType())) + .append(formatIfNotEmpty("%s", payload.deviceNumber())) + .append("") + .append(""); + return requestBuilder.toString(); + } +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinder.java new file mode 100644 index 0000000000..acfb6f3239 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinder.java @@ -0,0 +1,46 @@ +/* + * 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.profitbricks.binder.storage; + +import static java.lang.String.format; +import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder; +import org.jclouds.profitbricks.domain.Storage; + +public class CreateStorageRequestBinder extends BaseProfitBricksRequestBinder { + + protected final StringBuilder requestBuilder; + + CreateStorageRequestBinder() { + super("storage"); + this.requestBuilder = new StringBuilder(128 * 2); + } + + @Override + protected String createPayload(Storage.Request.CreatePayload payload) { + requestBuilder.append("") + .append("") + .append(format("%s", payload.dataCenterId())) + .append(formatIfNotEmpty("%s", payload.name())) + .append(format("%.0f", payload.size())) + .append(formatIfNotEmpty("%s", payload.mountImageId())) + .append(formatIfNotEmpty("%s", payload.profitBricksImagePassword())) + .append("") + .append(""); + return requestBuilder.toString(); + } + +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinder.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinder.java new file mode 100644 index 0000000000..9a80b83a28 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinder.java @@ -0,0 +1,47 @@ +/* + * 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.profitbricks.binder.storage; + +import static java.lang.String.format; +import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder; +import org.jclouds.profitbricks.domain.Storage; + +public class UpdateStorageRequestBinder extends BaseProfitBricksRequestBinder { + + protected final StringBuilder requestBuilder; + + UpdateStorageRequestBinder() { + super("storage"); + this.requestBuilder = new StringBuilder(128 * 2); + } + + @Override + protected String createPayload(Storage.Request.UpdatePayload payload) { + requestBuilder + .append("") + .append("") + .append(format("%s", payload.id())) + .append(formatIfNotEmpty("%.0f", payload.size())) + .append(formatIfNotEmpty("%s", payload.name())) + .append(formatIfNotEmpty("%s", payload.mountImageId())) + .append("") + .append(""); + + return requestBuilder.toString(); + } + +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java index 505624333d..f573eb0c7b 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java @@ -23,5 +23,5 @@ package org.jclouds.profitbricks.compute.internal; */ public enum ProvisioningStatusAware { - DATACENTER, SERVER; + DATACENTER, SERVER, STORAGE; } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java index 73db33f675..8a8a787b3c 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java @@ -26,9 +26,8 @@ import com.google.common.base.Predicate; /** * A custom predicate for waiting until a virtual resource satisfies the given expected status *

- * Performing api requests on a datacenter that is not {@link ProvisioningState#AVAILABLE} is not allowed. On some - * cases, the API user gets blocked from further requests, and will then need to contact tech support for api lock - * release. + * Performing api requests on a datacenter that is not {@link ProvisioningState#AVAILABLE} is not allowed. On some cases, the API user gets + * blocked from further requests, and will then need to contact tech support for api lock release. */ public class ProvisioningStatusPollingPredicate implements Predicate { @@ -49,7 +48,9 @@ public class ProvisioningStatusPollingPredicate implements Predicate { case DATACENTER: return expect == api.dataCenterApi().getDataCenterState(input); case SERVER: - return expect == api.serverApi().getServer( input ).state(); + return expect == api.serverApi().getServer(input).state(); + case STORAGE: + return expect == api.storageApi().getStorage(input).state(); default: throw new IllegalArgumentException("Unknown domain '" + domain + "'"); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/config/ProfitBricksHttpApiModule.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/config/ProfitBricksHttpApiModule.java index 57728be859..f95b1b3b9f 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/config/ProfitBricksHttpApiModule.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/config/ProfitBricksHttpApiModule.java @@ -55,14 +55,14 @@ public class ProfitBricksHttpApiModule extends HttpApiModule { @Override protected void configure() { - install(new SSLModule()); - bind(HttpCommandExecutorService.class).to(ResponseStatusFromPayloadHttpCommandExecutorService.class) - .in(Scopes.SINGLETON); + install(new SSLModule()); + bind(HttpCommandExecutorService.class).to(ResponseStatusFromPayloadHttpCommandExecutorService.class) + .in(Scopes.SINGLETON); } @Provides public ParseSax serviceFaultParser(ParseSax.Factory factory, Injector injector) { - return factory.create(injector.getInstance(ServiceFaultResponseHandler.class)); + return factory.create(injector.getInstance(ServiceFaultResponseHandler.class)); } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/AvailabilityZone.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/AvailabilityZone.java index b582d69f3c..97cac6971e 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/AvailabilityZone.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/AvailabilityZone.java @@ -24,10 +24,10 @@ public enum AvailabilityZone { return name(); } - public static AvailabilityZone fromValue( String v ) { + public static AvailabilityZone fromValue(String v) { try { - return valueOf( v ); - } catch ( Exception ex ) { + return valueOf(v); + } catch (Exception ex) { return UNRECOGNIZED; } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/DataCenter.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/DataCenter.java index d5f989301f..a24d84b6f0 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/DataCenter.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/DataCenter.java @@ -19,30 +19,43 @@ package org.jclouds.profitbricks.domain; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; +import java.util.List; import java.util.regex.Pattern; import org.jclouds.javax.annotation.Nullable; import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; @AutoValue public abstract class DataCenter { public abstract String id(); - @Nullable public abstract String name(); + @Nullable + public abstract String name(); public abstract int version(); - @Nullable public abstract ProvisioningState state(); + @Nullable + public abstract ProvisioningState state(); - @Nullable public abstract Location location(); + @Nullable + public abstract Location location(); -// @Nullable public abstract List servers(); -// @Nullable public abstract List storages(); + @Nullable + public abstract List servers(); + + @Nullable + public abstract List storages(); // @Nullable public abstract List loadBalancers(); - public static DataCenter create(String id, String name, int version, ProvisioningState state, Location location) { - return new AutoValue_DataCenter(id, name, version, state, location); + + public static DataCenter create(String id, String name, int version, ProvisioningState state, Location location, List servers, + List storages) { + return new AutoValue_DataCenter(id, name, version, state, location, + servers != null ? ImmutableList.copyOf(servers) : Lists.newArrayList(), + storages != null ? ImmutableList.copyOf(storages) : Lists.newArrayList()); } public static Builder builder() { @@ -60,76 +73,87 @@ public abstract class DataCenter { private ProvisioningState state; private Location location; private int version; -// private List servers; -// private List storage; + private List servers; + private List storages; // private List loadBalancer; public Builder id(String id) { - this.id = id; - return this; + this.id = id; + return this; } public Builder name(String name) { - this.name = name; - return this; + this.name = name; + return this; } public Builder state(ProvisioningState state) { - this.state = state; - return this; + this.state = state; + return this; } public Builder location(Location location) { - this.location = location; - return this; + this.location = location; + return this; } public Builder version(int version) { - this.version = version; - return this; + this.version = version; + return this; + } + + public Builder servers(List servers) { + this.servers = servers; + return this; + } + + public Builder storages(List storages) { + this.storages = storages; + return this; } public DataCenter build() { - return DataCenter.create(id, name, version, state, location); + return DataCenter.create(id, name, version, state, location, servers, storages); } public Builder fromDataCenter(DataCenter in) { - return this.id(in.id()).name(in.name()).version(in.version()).state(in.state()).location(in.location()); + return this.id(in.id()).name(in.name()).version(in.version()).state(in.state()).location(in.location()).servers(in.servers()) + .storages(in.storages()); } } public static final class Request { - + @AutoValue public abstract static class CreatePayload { - public abstract String name(); + public abstract String name(); - public abstract Location location(); + public abstract Location location(); - public static CreatePayload create(String name, Location location) { + public static CreatePayload create(String name, Location location) { checkInvalidChars(name); - return new AutoValue_DataCenter_Request_CreatePayload(name, location); - } + return new AutoValue_DataCenter_Request_CreatePayload(name, location); + } } @AutoValue public abstract static class UpdatePayload { - public abstract String id(); + public abstract String id(); - public abstract String name(); + public abstract String name(); - public static UpdatePayload create(String id, String name) { + public static UpdatePayload create(String id, String name) { checkInvalidChars(name); - return new AutoValue_DataCenter_Request_UpdatePayload(id, name); - } + return new AutoValue_DataCenter_Request_UpdatePayload(id, name); + } } - + private static final Pattern INVALID_CHARS = Pattern.compile("^.*[@/\\|'`’^].*$"); - - private static void checkInvalidChars(String name){ + + private static void checkInvalidChars(String name) { checkArgument(!isNullOrEmpty(name), "Name is required."); checkArgument(!INVALID_CHARS.matcher(name).matches(), "Name must not contain any of: @ / \\ | ' ` ’ ^"); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java index 969629a0ce..0354bf47d0 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java @@ -35,16 +35,16 @@ public enum Location { public static Location fromValue(String v) { try { - return valueOf(v); + return valueOf(v); } catch (IllegalArgumentException ex) { - return UNRECOGNIZED; + return UNRECOGNIZED; } } public static Location fromId(String id) { for (Location location : values()) - if (location.id.equals(id)) - return location; + if (location.id.equals(id)) + return location; return UNRECOGNIZED; } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ProvisioningState.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ProvisioningState.java index 2a9e0b63c5..833e979557 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ProvisioningState.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ProvisioningState.java @@ -22,9 +22,9 @@ public enum ProvisioningState { public static ProvisioningState fromValue(String value) { try { - return valueOf(value); + return valueOf(value); } catch (IllegalArgumentException e) { - return UNRECOGNIZED; + return UNRECOGNIZED; } } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Server.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Server.java index 703eb59e1d..6149cfd743 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Server.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Server.java @@ -17,12 +17,20 @@ package org.jclouds.profitbricks.domain; import org.jclouds.profitbricks.domain.internal.ServerCommonProperties; + import com.google.auto.value.AutoValue; + import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Date; +import java.util.List; + import org.jclouds.javax.annotation.Nullable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + @AutoValue public abstract class Server implements ServerCommonProperties { @@ -34,10 +42,10 @@ public abstract class Server implements ServerCommonProperties { return name(); } - public static Status fromValue( String v ) { + public static Status fromValue(String v) { try { - return valueOf( v ); - } catch ( IllegalArgumentException ex ) { + return valueOf(v); + } catch (IllegalArgumentException ex) { return UNRECOGNIZED; } } @@ -70,13 +78,17 @@ public abstract class Server implements ServerCommonProperties { @Nullable public abstract Date lastModificationTime(); -// public abstract List storages(); -// public abstract List storages(); - public static Server create( String id, String name, int cores, int ram, Boolean hasInternetAccess, ProvisioningState state, - Status status, OsType osType, AvailabilityZone availabilityZone, Date creationTime, Date lastModificationTime, Boolean isCpuHotPlug, - Boolean isRamHotPlug, Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) { - return new AutoValue_Server( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, isDiscVirtioHotUnPlug, - cores, ram, id, name, hasInternetAccess, state, status, osType, availabilityZone, creationTime, lastModificationTime ); + @Nullable + public abstract List storages(); + +// public abstract List nics(); + public static Server create(String id, String name, int cores, int ram, Boolean hasInternetAccess, ProvisioningState state, + Status status, OsType osType, AvailabilityZone availabilityZone, Date creationTime, Date lastModificationTime, + List storages, Boolean isCpuHotPlug, Boolean isRamHotPlug, Boolean isNicHotPlug, Boolean isNicHotUnPlug, + Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug) { + return new AutoValue_Server(isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, isDiscVirtioHotUnPlug, + cores, ram, id, name, hasInternetAccess, state, status, osType, availabilityZone, creationTime, lastModificationTime, + storages != null ? ImmutableList.copyOf(storages) : Lists.newArrayList()); } @@ -85,7 +97,7 @@ public abstract class Server implements ServerCommonProperties { } public DescribingBuilder toBuilder() { - return builder().fromServer( this ); + return builder().fromServer(this); } public abstract static class Builder { @@ -100,48 +112,48 @@ public abstract class Server implements ServerCommonProperties { protected Boolean discVirtioHotPlug; protected Boolean discVirtioHotUnPlug; - public B name( String name ) { + public B name(String name) { this.name = name; return self(); } - public B cores( int cores ) { + public B cores(int cores) { this.cores = cores; return self(); } - public B ram( int ram ) { + public B ram(int ram) { this.ram = ram; return self(); } - public B isCpuHotPlug( Boolean cpuHotPlug ) { + public B isCpuHotPlug(Boolean cpuHotPlug) { this.cpuHotPlug = cpuHotPlug; return self(); } - public B isRamHotPlug( Boolean ramHotPlug ) { + public B isRamHotPlug(Boolean ramHotPlug) { this.ramHotPlug = ramHotPlug; return self(); } - public B isNicHotPlug( Boolean nicHotPlug ) { + public B isNicHotPlug(Boolean nicHotPlug) { this.nicHotPlug = nicHotPlug; return self(); } - public B isNicHotUnPlug( Boolean nicHotUnPlug ) { + public B isNicHotUnPlug(Boolean nicHotUnPlug) { this.nicHotUnPlug = nicHotUnPlug; return self(); } - public B isDiscVirtioHotPlug( Boolean discVirtioHotPlug ) { + public B isDiscVirtioHotPlug(Boolean discVirtioHotPlug) { this.discVirtioHotPlug = discVirtioHotPlug; return self(); } - public B isDiscVirtioHotUnPlug( Boolean discVirtioHotUnPlug ) { + public B isDiscVirtioHotUnPlug(Boolean discVirtioHotUnPlug) { this.discVirtioHotUnPlug = discVirtioHotUnPlug; return self(); } @@ -161,59 +173,65 @@ public abstract class Server implements ServerCommonProperties { private Date creationTime; private Date lastModificationTime; private Boolean hasInternetAccess; + private List storages; - public DescribingBuilder id( String id ) { + public DescribingBuilder id(String id) { this.id = id; return this; } - public DescribingBuilder state( ProvisioningState state ) { + public DescribingBuilder state(ProvisioningState state) { this.state = state; return this; } - public DescribingBuilder status( Status status ) { + public DescribingBuilder status(Status status) { this.status = status; return this; } - public DescribingBuilder osType( OsType osType ) { + public DescribingBuilder osType(OsType osType) { this.osType = osType; return this; } - public DescribingBuilder availabilityZone( AvailabilityZone zone ) { + public DescribingBuilder availabilityZone(AvailabilityZone zone) { this.zone = zone; return this; } - public DescribingBuilder creationTime( Date creationTime ) { + public DescribingBuilder creationTime(Date creationTime) { this.creationTime = creationTime; return this; } - public DescribingBuilder lastModificationTime( Date lastModificationTime ) { + public DescribingBuilder lastModificationTime(Date lastModificationTime) { this.lastModificationTime = lastModificationTime; return this; } - public DescribingBuilder hasInternetAccess( Boolean hasInternetAccess ) { + public DescribingBuilder hasInternetAccess(Boolean hasInternetAccess) { this.hasInternetAccess = hasInternetAccess; return this; } + public DescribingBuilder storages(List storages) { + this.storages = storages; + return this; + } + @Override public Server build() { - return Server.create( id, name, cores, ram, hasInternetAccess, state, status, osType, zone, creationTime, - lastModificationTime, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug ); + return Server.create(id, name, cores, ram, hasInternetAccess, state, status, osType, zone, creationTime, + lastModificationTime, storages, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug); } - private DescribingBuilder fromServer( Server in ) { - return this.id( in.id() ).cores( in.cores() ).creationTime( in.creationTime() ).hasInternetAccess( in.hasInternetAccess() ) - .isCpuHotPlug( in.isCpuHotPlug() ).isDiscVirtioHotPlug( in.isDiscVirtioHotPlug() ).isDiscVirtioHotUnPlug( in.isDiscVirtioHotUnPlug() ) - .isNicHotPlug( in.isNicHotPlug() ).isNicHotUnPlug( in.isNicHotUnPlug() ).isRamHotPlug( in.isRamHotPlug() ) - .lastModificationTime( in.lastModificationTime() ).name( in.name() ).osType( in.osType() ).ram( in.ram() ).state( in.state() ) - .status( in.status() ); + private DescribingBuilder fromServer(Server in) { + return this.id(in.id()).cores(in.cores()).creationTime(in.creationTime()).hasInternetAccess(in.hasInternetAccess()) + .isCpuHotPlug(in.isCpuHotPlug()).isDiscVirtioHotPlug(in.isDiscVirtioHotPlug()).isDiscVirtioHotUnPlug(in.isDiscVirtioHotUnPlug()) + .isNicHotPlug(in.isNicHotPlug()).isNicHotUnPlug(in.isNicHotUnPlug()).isRamHotPlug(in.isRamHotPlug()) + .lastModificationTime(in.lastModificationTime()).name(in.name()).osType(in.osType()).ram(in.ram()).state(in.state()) + .status(in.status()).storages(in.storages()); } @Override @@ -256,18 +274,18 @@ public abstract class Server implements ServerCommonProperties { @Nullable public abstract OsType osType(); - public static CreatePayload create( String dataCenterId, String name, int core, int ram ) { - return create( dataCenterId, name, core, ram, "", "", null, false, null, null, null, null, null, null, null, null ); + public static CreatePayload create(String dataCenterId, String name, int core, int ram) { + return create(dataCenterId, name, core, ram, "", "", null, false, null, null, null, null, null, null, null, null); } - public static CreatePayload create( String dataCenterId, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId, + public static CreatePayload create(String dataCenterId, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId, Integer lanId, Boolean hasInternetAccess, AvailabilityZone availabilityZone, OsType osType, Boolean isCpuHotPlug, Boolean isRamHotPlug, - Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) { - validateCores( cores ); - validateRam( ram, isRamHotPlug ); - return new AutoValue_Server_Request_CreatePayload( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, + Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug) { + validateCores(cores); + validateRam(ram, isRamHotPlug); + return new AutoValue_Server_Request_CreatePayload(isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, isDiscVirtioHotUnPlug, name, cores, ram, dataCenterId, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess, - availabilityZone, osType ); + availabilityZone, osType); } public static class Builder extends Server.Builder { @@ -280,42 +298,42 @@ public abstract class Server implements ServerCommonProperties { private AvailabilityZone availabilityZone; private OsType osType; - public Builder dataCenterId( String dataCenterId ) { + public Builder dataCenterId(String dataCenterId) { this.dataCenterId = dataCenterId; return this; } - public Builder dataCenterId( DataCenter dataCenter ) { - this.dataCenterId = checkNotNull( dataCenter, "Cannot pass null datacenter" ).id(); + public Builder dataCenterId(DataCenter dataCenter) { + this.dataCenterId = checkNotNull(dataCenter, "Cannot pass null datacenter").id(); return this; } - public Builder bootFromStorageId( String storageId ) { + public Builder bootFromStorageId(String storageId) { this.bootFromStorageId = storageId; return this; } - public Builder bootFromImageId( String image ) { + public Builder bootFromImageId(String image) { this.bootFromImageId = image; return this; } - public Builder lanId( Integer lanId ) { + public Builder lanId(Integer lanId) { this.lanId = lanId; return this; } - public Builder availabilityZone( AvailabilityZone zone ) { + public Builder availabilityZone(AvailabilityZone zone) { this.availabilityZone = zone; return this; } - public Builder osType( OsType osType ) { + public Builder osType(OsType osType) { this.osType = osType; return this; } - public Builder hasInternetAccess( Boolean hasInternetAccess ) { + public Builder hasInternetAccess(Boolean hasInternetAccess) { this.hasInternetAccess = hasInternetAccess; return this; } @@ -327,8 +345,8 @@ public abstract class Server implements ServerCommonProperties { @Override public CreatePayload build() { - return CreatePayload.create( dataCenterId, name, cores, ram, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess, - availabilityZone, osType, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug ); + return CreatePayload.create(dataCenterId, name, cores, ram, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess, + availabilityZone, osType, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug); } } @@ -355,11 +373,11 @@ public abstract class Server implements ServerCommonProperties { @Nullable public abstract OsType osType(); - public static UpdatePayload create( String id, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId, + public static UpdatePayload create(String id, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId, AvailabilityZone availabilityZone, OsType osType, Boolean isCpuHotPlug, Boolean isRamHotPlug, Boolean isNicHotPlug, - Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) { - return new AutoValue_Server_Request_UpdatePayload( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, - isDiscVirtioHotUnPlug, cores, ram, name, id, bootFromStorageId, bootFromImageId, availabilityZone, osType ); + Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug) { + return new AutoValue_Server_Request_UpdatePayload(isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, + isDiscVirtioHotUnPlug, cores, ram, name, id, bootFromStorageId, bootFromImageId, availabilityZone, osType); } public static class Builder extends Server.Builder { @@ -370,27 +388,27 @@ public abstract class Server implements ServerCommonProperties { private AvailabilityZone availabilityZone; private OsType osType; - public Builder id( String id ) { + public Builder id(String id) { this.id = id; return this; } - public Builder bootFromStorageId( String storageId ) { + public Builder bootFromStorageId(String storageId) { this.bootFromStorageId = storageId; return this; } - public Builder bootFromImageId( String image ) { + public Builder bootFromImageId(String image) { this.bootFromImageId = image; return this; } - public Builder availabilityZone( AvailabilityZone zone ) { + public Builder availabilityZone(AvailabilityZone zone) { this.availabilityZone = zone; return this; } - public Builder osType( OsType osType ) { + public Builder osType(OsType osType) { this.osType = osType; return this; } @@ -402,8 +420,8 @@ public abstract class Server implements ServerCommonProperties { @Override public UpdatePayload build() { - return UpdatePayload.create( id, name, cores, ram, bootFromStorageId, bootFromImageId, availabilityZone, osType, - cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug ); + return UpdatePayload.create(id, name, cores, ram, bootFromStorageId, bootFromImageId, availabilityZone, osType, + cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug); } @@ -412,13 +430,13 @@ public abstract class Server implements ServerCommonProperties { } - private static void validateCores( int cores ) { - checkArgument( cores > 0, "Core must be atleast 1." ); + private static void validateCores(int cores) { + checkArgument(cores > 0, "Core must be atleast 1."); } - private static void validateRam( int ram, Boolean isRamHotPlug ) { - int minRam = ( isRamHotPlug == null || !isRamHotPlug ) ? 256 : 1024; - checkArgument( ram >= minRam && ram % 256 == 0, "RAM must be multiples of 256 with minimum of 256 MB (1024 MB if ramHotPlug is enabled)" ); + private static void validateRam(int ram, Boolean isRamHotPlug) { + int minRam = (isRamHotPlug == null || !isRamHotPlug) ? 256 : 1024; + checkArgument(ram >= minRam && ram % 256 == 0, "RAM must be multiples of 256 with minimum of 256 MB (1024 MB if ramHotPlug is enabled)"); } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ServiceFault.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ServiceFault.java index 0e1303ea3f..dac8f0bd26 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ServiceFault.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/ServiceFault.java @@ -36,11 +36,11 @@ public abstract class ServiceFault { UNRECOGNIZED; public static FaultCode fromValue(String v) { - try { - return valueOf(v); - } catch (IllegalArgumentException ex) { - return UNRECOGNIZED; - } + try { + return valueOf(v); + } catch (IllegalArgumentException ex) { + return UNRECOGNIZED; + } } } @@ -68,27 +68,27 @@ public abstract class ServiceFault { private int requestId; public Builder faultCode(FaultCode code) { - this.faultCode = code; - return this; + this.faultCode = code; + return this; } public Builder httpCode(int httpCode) { - this.httpCode = httpCode; - return this; + this.httpCode = httpCode; + return this; } public Builder message(String message) { - this.message = message; - return this; + this.message = message; + return this; } public Builder requestId(int requestId) { - this.requestId = requestId; - return this; + this.requestId = requestId; + return this; } public ServiceFault build() { - return create(faultCode, httpCode, message, requestId); + return create(faultCode, httpCode, message, requestId); } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Storage.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Storage.java new file mode 100644 index 0000000000..6dcaf25230 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Storage.java @@ -0,0 +1,355 @@ +/* + * 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.profitbricks.domain; + +import com.google.auto.value.AutoValue; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Date; +import java.util.List; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + +@AutoValue +public abstract class Storage { + + public enum BusType { + + IDE, SCSI, VIRTIO, UNRECOGNIZED; + + public static BusType fromValue(String value) { + try { + return valueOf(value); + } catch (IllegalArgumentException ex) { + return UNRECOGNIZED; + } + } + } + + public abstract String id(); + + @Nullable + public abstract String name(); + + public abstract float size(); // GB + + @Nullable + public abstract Date creationTime(); + + @Nullable + public abstract Date lastModificationTime(); + + public abstract ProvisioningState state(); + + @Nullable + public abstract List serverIds(); + + @Nullable + public abstract Boolean bootDevice(); + + @Nullable + public abstract BusType busType(); + + @Nullable + public abstract Integer deviceNumber(); + + public static Storage create(String id, String name, float size, Date creationTime, Date lastModificationTime, + ProvisioningState state, List serverIds, Boolean bootDevice, BusType busType, Integer deviceNumber) { + return new AutoValue_Storage(id, name, size, creationTime, lastModificationTime, state, + serverIds != null ? ImmutableList.copyOf(serverIds) : Lists.newArrayList(), + bootDevice, busType, deviceNumber); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromStorage(this); + } + + public static class Builder { + + private String id; + private String name; + private float size; + private Date creationTime; + private Date lastModificationTime; + private ProvisioningState state; + private List serverIds; + private Boolean bootDevice; + private BusType busType; + private Integer deviceNumber; + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder size(float size) { + this.size = size; + return this; + } + + public Builder creationTime(Date creationTime) { + this.creationTime = creationTime; + return this; + } + + public Builder lastModificationTime(Date lastModificationTime) { + this.lastModificationTime = lastModificationTime; + return this; + } + + public Builder state(ProvisioningState state) { + this.state = state; + return this; + } + + public Builder serverIds(List serverIds) { + this.serverIds = serverIds; + return this; + } + + public Builder bootDevice(Boolean bootDevice) { + this.bootDevice = bootDevice; + return this; + } + + public Builder busType(BusType busType) { + this.busType = busType; + return this; + } + + public Builder deviceNumber(Integer deviceNumber) { + this.deviceNumber = deviceNumber; + return this; + } + + private Builder fromStorage(Storage in) { + return this.id(in.id()).name(in.name()).size(in.size()).creationTime(in.creationTime()) + .lastModificationTime(in.lastModificationTime()).state(in.state()).serverIds(in.serverIds()) + .bootDevice(in.bootDevice()).busType(in.busType()).deviceNumber(in.deviceNumber()); + } + + public Storage build() { + return Storage.create(id, name, size, creationTime, lastModificationTime, state, serverIds, bootDevice, busType, deviceNumber); + } + + } + + public static final class Request { + + public static CreatePayload.Builder creatingBuilder() { + return new CreatePayload.Builder(); + } + + public static UpdatePayload.Builder updatingBuilder() { + return new UpdatePayload.Builder(); + } + + public static ConnectPayload.Builder connectingBuilder() { + return new ConnectPayload.Builder(); + } + + @AutoValue + public abstract static class CreatePayload { + + public abstract String dataCenterId(); + + public abstract float size(); + + @Nullable + public abstract String name(); + + @Nullable + public abstract String mountImageId(); + + @Nullable + public abstract String profitBricksImagePassword(); + + public static CreatePayload create(String dataCenterId, float size, String name, String mountImageId, String imagePassword) { + validateSize(size); + return new AutoValue_Storage_Request_CreatePayload(dataCenterId, size, name, mountImageId, imagePassword); + } + + public static class Builder { + + private String dataCenterId; + private float size; + private String name; + private String mountImageId; + private String profitBricksImagePassword; + + public Builder dataCenterId(String dataCenterId) { + this.dataCenterId = dataCenterId; + return this; + } + + public Builder dataCenterId(DataCenter dataCenter) { + this.dataCenterId = checkNotNull(dataCenter, "Cannot pass null datacenter").id(); + return this; + } + + public Builder size(float size) { + this.size = size; + return this; + } + + public Builder mountImageId(String mountImageId) { + this.mountImageId = mountImageId; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder imagePassword(String password) { + this.profitBricksImagePassword = password; + return this; + } + + public CreatePayload build() { + return CreatePayload.create(dataCenterId, size, name, mountImageId, profitBricksImagePassword); + } + } + + } + + @AutoValue + public abstract static class UpdatePayload { + + public abstract String id(); + + @Nullable + public abstract Float size(); + + @Nullable + public abstract String name(); + + @Nullable + public abstract String mountImageId(); + + public static UpdatePayload create(String id, Float size, String name, String mountImageId) { + validateSize(size); + return new AutoValue_Storage_Request_UpdatePayload(id, size, name, mountImageId); + } + + public static class Builder { + + private String id; + private Float size; + private String name; + private String mountImageId; + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder size(float size) { + this.size = size; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder mountImageId(String mountImageId) { + this.mountImageId = mountImageId; + return this; + } + + public UpdatePayload build() { + return UpdatePayload.create(id, size, name, mountImageId); + } + } + } + + @AutoValue + public abstract static class ConnectPayload { + + public abstract String storageId(); + + public abstract String serverId(); + + @Nullable + public abstract BusType busType(); + + @Nullable + public abstract Integer deviceNumber(); + + public static ConnectPayload create(String storageId, String serverId, BusType busType, Integer deviceNumber) { + return new AutoValue_Storage_Request_ConnectPayload(storageId, serverId, busType, deviceNumber); + } + + public static class Builder { + + private String storageId; + private String serverId; + private BusType busType; + private Integer deviceNumber; + + public Builder storageId(String storageId) { + this.storageId = storageId; + return this; + } + + public Builder serverId(String serverId) { + this.serverId = serverId; + return this; + } + + public Builder busType(BusType busType) { + this.busType = busType; + return this; + } + + public Builder deviceNumber(Integer deviceNumber) { + this.deviceNumber = deviceNumber; + return this; + } + + public ConnectPayload build() { + return ConnectPayload.create(storageId, serverId, busType, deviceNumber); + } + + } + } + + private static void validateSize(Float size) { + if (size != null) + checkArgument(size > 1, "Storage size must be > 1GB"); + + } + } + +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java index f6607303fb..a9c6143261 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java @@ -58,8 +58,7 @@ public interface DataCenterApi { /** * @param identifier Data Center identifier - * @return Returns information about an existing virtual data center's state and configuration or null - * if it doesn't exist. + * @return Returns information about an existing virtual data center's state and configuration or null if it doesn't exist. */ @POST @Named("datacenter:get") @@ -69,8 +68,8 @@ public interface DataCenterApi { DataCenter getDataCenter(@PayloadParam("id") String identifier); /** - * This is a lightweight function for polling the current provisioning state of the Virtual Data Center. It is - * recommended to use this function for large Virtual Data Centers to query request results. + * This is a lightweight function for polling the current provisioning state of the Virtual Data Center. It is recommended to use this + * function for large Virtual Data Centers to query request results. *

* @param identifier Data Center identifier */ @@ -119,9 +118,8 @@ public interface DataCenterApi { DataCenter clearDataCenter(@PayloadParam("id") String identifier); /** - * Deletes an Virtual Data Center. If a previous request on the target data center is still in progress, the data - * center is going to be deleted after this request has been completed. Once a Data Center has been deleted, no - * further request can be performed on it. + * Deletes an Virtual Data Center. If a previous request on the target data center is still in progress, the data center is going to be + * deleted after this request has been completed. Once a Data Center has been deleted, no further request can be performed on it. *

* @param identifier Identifier of the virtual data center * @return Returns a boolean indicating whether delete operation was made diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ServerApi.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ServerApi.java index 1fa89b3ee8..34445da098 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ServerApi.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ServerApi.java @@ -39,19 +39,19 @@ import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; -@RequestFilters( { BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class } ) -@Consumes( MediaType.TEXT_XML ) -@Produces( MediaType.TEXT_XML ) +@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class}) +@Consumes(MediaType.TEXT_XML) +@Produces(MediaType.TEXT_XML) public interface ServerApi { /** * @return Returns information about all virtual server, such as configuration, provisioning status, power status, etc. */ @POST - @Named( "server:getall" ) - @Payload( "" ) - @XMLResponseParser( ServerListResponseHandler.class ) - @Fallback( Fallbacks.EmptyListOnNotFoundOr404.class ) + @Named("server:getall") + @Payload("") + @XMLResponseParser(ServerListResponseHandler.class) + @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class) List getAllServers(); /** @@ -59,11 +59,11 @@ public interface ServerApi { * @return Returns information about a virtual server, such as configuration, provisioning status, power status, etc. */ @POST - @Named( "server:get" ) - @Payload( "{id}" ) - @XMLResponseParser( ServerInfoResponseHandler.class ) - @Fallback( Fallbacks.NullOnNotFoundOr404.class ) - Server getServer( @PayloadParam( "id" ) String identifier ); + @Named("server:get") + @Payload("{id}") + @XMLResponseParser(ServerInfoResponseHandler.class) + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + Server getServer(@PayloadParam("id") String identifier); /** * Starts an existing virtual server @@ -77,10 +77,10 @@ public interface ServerApi { * @return Identifier of current request */ @POST - @Named( "server:start" ) - @Payload( "{id}" ) - @XMLResponseParser( RequestIdOnlyResponseHandler.class ) - String startServer( @PayloadParam( "id" ) String id ); + @Named("server:start") + @Payload("{id}") + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String startServer(@PayloadParam("id") String id); /** * @@ -99,10 +99,10 @@ public interface ServerApi { * @return Identifier of current request */ @POST - @Named( "server:stop" ) - @Payload( "{id}" ) - @XMLResponseParser( RequestIdOnlyResponseHandler.class ) - String stopServer( @PayloadParam( "id" ) String id ); + @Named("server:stop") + @Payload("{id}") + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String stopServer(@PayloadParam("id") String id); /** * Resets an existing virtual server (POWER CYCLE). @@ -119,10 +119,10 @@ public interface ServerApi { * @return Identifier of current request */ @POST - @Named( "server:reset" ) - @Payload( "{id}" ) - @XMLResponseParser( RequestIdOnlyResponseHandler.class ) - String resetServer( @PayloadParam( "id" ) String id ); + @Named("server:reset") + @Payload("{id}") + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String resetServer(@PayloadParam("id") String id); /** * Creates a Virtual Server within an existing data center. Parameters can be specified to set up a boot device and connect the server to @@ -132,22 +132,22 @@ public interface ServerApi { * @return serverId of the created server */ @POST - @Named( "server:create" ) - @MapBinder( CreateServerRequestBinder.class ) - @XMLResponseParser( ServerIdOnlyResponseHandler.class ) - String createServer( @PayloadParam( "server" ) Server.Request.CreatePayload payload ); + @Named("server:create") + @MapBinder(CreateServerRequestBinder.class) + @XMLResponseParser(ServerIdOnlyResponseHandler.class) + String createServer(@PayloadParam("server") Server.Request.CreatePayload payload); /** * Updates parameters of an existing virtual server device. * - * @param payload Paylaod + * @param payload Payload * @return Identifier of current request */ @POST - @Named( "server:update" ) - @MapBinder( UpdateServerRequestBinder.class ) - @XMLResponseParser( RequestIdOnlyResponseHandler.class ) - String updateServer( @PayloadParam( "server" ) Server.Request.UpdatePayload payload ); + @Named("server:update") + @MapBinder(UpdateServerRequestBinder.class) + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String updateServer(@PayloadParam("server") Server.Request.UpdatePayload payload); /** * Deletes an existing Virtual Server. @@ -156,9 +156,9 @@ public interface ServerApi { * @return Identifier of current request */ @POST - @Named( "server:delete" ) - @Payload( "{id}" ) - @Fallback( Fallbacks.FalseOnNotFoundOr404.class ) - boolean deleteServer( @PayloadParam( "id" ) String id ); + @Named("server:delete") + @Payload("{id}") + @Fallback(Fallbacks.FalseOnNotFoundOr404.class) + boolean deleteServer(@PayloadParam("id") String id); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/StorageApi.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/StorageApi.java new file mode 100644 index 0000000000..f5d3577be0 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/StorageApi.java @@ -0,0 +1,136 @@ +/* + * 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.profitbricks.features; + +import java.util.List; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.profitbricks.binder.storage.ConnectStorageToServerRequestBinder; +import org.jclouds.profitbricks.binder.storage.CreateStorageRequestBinder; +import org.jclouds.profitbricks.binder.storage.UpdateStorageRequestBinder; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope; +import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler; +import org.jclouds.profitbricks.http.parser.storage.StorageIdOnlyResponseHandler; +import org.jclouds.profitbricks.http.parser.storage.StorageInfoResponseHandler; +import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.XMLResponseParser; + +@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class}) +@Consumes(MediaType.TEXT_XML) +@Produces(MediaType.TEXT_XML) +public interface StorageApi { + + /** + * + * @return Returns information about all virtual storage, such as configuration and provisioning state. + */ + @POST + @Named("storage:getall") + @Payload("") + @XMLResponseParser(StorageListResponseHandler.class) + @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class) + List getAllStorages(); + + /** + * + * @param id Storage identifier + * @return Returns information about a virtual storage’s configuration and provisioning state. + */ + @POST + @Named("storage:get") + @Payload("{id}") + @XMLResponseParser(StorageInfoResponseHandler.class) + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + Storage getStorage(@PayloadParam("id") String id); + + /** + * Creates a virtual storage within an existing virtual data center. Additional parameters can be specified, e.g. for assigning a HDD + * image to the storage. + * + * @param payload Payload + * @return storageId of the created storage + */ + @POST + @Named("storage:create") + @MapBinder(CreateStorageRequestBinder.class) + @XMLResponseParser(StorageIdOnlyResponseHandler.class) + String createStorage(@PayloadParam("storage") Storage.Request.CreatePayload payload); + + /** + * Updates parameters of an existing virtual storage device. It is possible to increase the storage size without reboot of an already + * provisioned storage. The additional capacity is not added to any partition. You have to partition the storage afterwards. Vice versa, + * it is not possible to decrease the storage size of an already provisioned storage. + * + * @param payload Payload + * @return Identifier of current request + */ + @POST + @Named("storage:update") + @MapBinder(UpdateStorageRequestBinder.class) + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String updateStorage(@PayloadParam("storage") Storage.Request.UpdatePayload payload); + + /** + * Deletes an existing virtual storage device. + * + * @param id Identifier of the target virtual storage + * @return Identifier of current request + */ + @POST + @Named("storage:delete") + @Payload("{id}") + @Fallback(Fallbacks.FalseOnNotFoundOr404.class) + boolean deleteStorage(@PayloadParam("id") String id); + + /** + * Connects a virtual storage device to an existing server. + * + * @param payload Payload + * @return Identifier of current request + */ + @POST + @Named("storage:connect") + @MapBinder(ConnectStorageToServerRequestBinder.class) + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String connectStorageToServer(@PayloadParam("storage") Storage.Request.ConnectPayload payload); + + /** + * Disconnects a virtual storage device from a connected server. + * + * @param storageId Identifier of the connected virtual storage + * @param serverId Identifier of the connected virtual server + * @return Identifier of current request + */ + @POST + @Named("storage:disconnect") + @Payload("{storageId}{serverId}") + @XMLResponseParser(RequestIdOnlyResponseHandler.class) + String disconnectStorageFromServer(@PayloadParam("storageId") String storageId, @PayloadParam("serverId") String serverId); +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java index 6453327de0..a4ecb50667 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/handlers/ProfitBricksHttpErrorHandler.java @@ -23,6 +23,7 @@ import javax.inject.Singleton; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.InsufficientResourcesException; import org.jclouds.rest.ResourceNotFoundException; @@ -40,31 +41,35 @@ public class ProfitBricksHttpErrorHandler implements HttpErrorHandler { public void handleError(final HttpCommand command, final HttpResponse response) { Exception exception = null; try { - switch (response.getStatusCode()) { - case 400: - case 405: - exception = new IllegalArgumentException(response.getMessage(), exception); - break; - case 401: - exception = new AuthorizationException(response.getMessage(), exception); - break; - case 402: - case 409: - exception = new IllegalStateException(response.getMessage(), exception); - break; - case 404: - case 410: - if (!command.getCurrentRequest().getMethod().equals("DELETE")) - exception = new ResourceNotFoundException(response.getMessage(), exception); - break; - case 413: - case 503: - exception = new InsufficientResourcesException(response.getMessage(), exception); - break; - } + switch (response.getStatusCode()) { + case 400: + case 405: + exception = new IllegalArgumentException(response.getMessage(), exception); + break; + case 401: + exception = new AuthorizationException("This request requires authentication.", exception); + break; + case 402: + case 409: + exception = new IllegalStateException(response.getMessage(), exception); + break; + case 404: + case 410: + if (!command.getCurrentRequest().getMethod().equals("DELETE")) + exception = new ResourceNotFoundException(response.getMessage(), exception); + break; + case 413: + case 503: + // if nothing (default message was OK) was parsed from command executor, assume it was an 503 (Maintenance) html response. + if (response.getMessage().equals("OK")) + exception = new HttpResponseException("The ProfitBricks team is currently carrying out maintenance.", command, response); + else + exception = new InsufficientResourcesException(response.getMessage(), exception); + break; + } } finally { - closeQuietly(response.getPayload()); - command.setException(exception); + closeQuietly(response.getPayload()); + command.setException(exception); } } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorService.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorService.java index 78b0c8b248..b818d3def7 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorService.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorService.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URI; +import java.util.regex.Pattern; import javax.inject.Named; import javax.inject.Singleton; @@ -51,20 +52,22 @@ import com.google.inject.Inject; /** * Custom implementation of the HTTP driver to read actual http status and message from SOAP Fault. *
- * ProfitBricks API errors are always returned with 500 HTTP code. This class parses and reads the SOAP response to map the actual http code - * and message + * ProfitBricks API errors are always returned with 500 HTTP code. This class parses and reads the SOAP response to map + * the actual http code and message */ @Singleton public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrlHttpCommandExecutorService { private final ParseSax faultHandler; + private static final Pattern endSoapTag = Pattern.compile("$"); + @Inject ResponseStatusFromPayloadHttpCommandExecutorService(HttpUtils utils, ContentMetadataCodec contentMetadataCodec, - DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler, - DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier, - @Named("untrusted") Supplier untrustedSSLContextProvider, Function proxyForURI, - ParseSax faultHandler) { + DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler, + DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier, + @Named("untrusted") Supplier untrustedSSLContextProvider, Function proxyForURI, + ParseSax faultHandler) { super(utils, contentMetadataCodec, retryHandler, ioRetryHandler, errorHandler, wire, verifier, untrustedSSLContextProvider, proxyForURI); this.faultHandler = faultHandler; } @@ -74,38 +77,40 @@ public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrl HttpResponse originalResponse = super.invoke(connection); HttpResponse.Builder responseBuilder = originalResponse.toBuilder(); - if (hasPayload(originalResponse) && hasServerError(originalResponse)) { - // As we need to read the response body to determine if there are errors, but we may need to process the body - // again later in the response parsers if everything is OK, we buffer the body into an InputStream we can reset - InputStream in = null; - InputStream originalInputStream = originalResponse.getPayload().openStream(); - if (originalInputStream instanceof ByteArrayInputStream) - in = originalInputStream; - else - try { - in = new ByteArrayInputStream(ByteStreams.toByteArray(originalInputStream)); - } finally { - closeQuietly(originalInputStream); - } + if (hasServerError(originalResponse) && hasPayload(originalResponse)) { + // As we need to read the response body to determine if there are errors, but we may need to process the body + // again later in the response parsers if everything is OK, we buffer the body into an InputStream we can reset + InputStream in = null; + InputStream originalInputStream = originalResponse.getPayload().openStream(); - try { - ServiceFault fault = faultHandler.parse(in); - if (fault != null) - responseBuilder - .statusCode(fault.httpCode()) - .message(fault.message()); - } catch (Exception ex) { - // ignore - } finally { - // Reset the input stream and set the payload, so it can be read again - // by the response and error parsers - if (in != null) { - in.reset(); - Payload payload = Payloads.newInputStreamPayload(in); - contentMetadataCodec.fromHeaders(payload.getContentMetadata(), originalResponse.getHeaders()); - responseBuilder.payload(payload); - } - } + if (originalInputStream instanceof ByteArrayInputStream) + in = originalInputStream; + else + try { + in = new ByteArrayInputStream(ByteStreams.toByteArray(originalInputStream)); + } finally { + closeQuietly(originalInputStream); + } + try { + if (isSoapPayload(in)) { + ServiceFault fault = faultHandler.parse(in); + if (fault != null) + responseBuilder + .statusCode(fault.httpCode()) + .message(fault.message()); + } + } catch (Exception ex) { + // ignore + } finally { + // Reset the input stream and set the payload, so it can be read again + // by the response and error parsers + if (in != null) { + in.reset(); + Payload payload = Payloads.newInputStreamPayload(in); + contentMetadataCodec.fromHeaders(payload.getContentMetadata(), originalResponse.getHeaders()); + responseBuilder.payload(payload); + } + } } return responseBuilder.build(); @@ -119,4 +124,17 @@ public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrl return response.getPayload() != null && response.getPayload().getRawContent() != null; } + private static boolean isSoapPayload(final InputStream is) throws IOException { + int size = is.available(); + char[] chars = new char[size]; + byte[] bytes = new byte[size]; + + is.read(bytes, 0, size); + for (int i = 0; i < size;) + chars[i] = (char) (bytes[i++] & 0xff); + + is.reset(); // throws premature end of file w/o this + + return endSoapTag.matcher(new String(chars)).find(); + } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelope.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelope.java index fce8e21fdb..7f2131d9f2 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelope.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelope.java @@ -32,9 +32,9 @@ import org.jclouds.io.Payloads; public class ProfitBricksSoapMessageEnvelope implements HttpRequestFilter { private final String SOAP_PREFIX - = "" - + "" - + ""; + = "" + + "" + + ""; private final String SOAP_SUFFIX = ""; diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/BaseProfitBricksResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/BaseProfitBricksResponseHandler.java index c61f2b5a34..6a9933f5dc 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/BaseProfitBricksResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/BaseProfitBricksResponseHandler.java @@ -16,23 +16,14 @@ */ package org.jclouds.profitbricks.http.parser; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Date; - -import org.jclouds.date.DateCodec; -import org.jclouds.date.DateCodecFactory; import org.jclouds.http.functions.ParseSax; import org.xml.sax.SAXException; public abstract class BaseProfitBricksResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult { - protected final DateCodec dateCodec; - private final StringBuilder strBuilder; - public BaseProfitBricksResponseHandler(DateCodecFactory dateCodec) { - this.dateCodec = checkNotNull(checkNotNull(dateCodec, "dateCodecFactory null").iso8601(), "iso8601 date codec null"); + public BaseProfitBricksResponseHandler() { this.strBuilder = new StringBuilder(); } @@ -41,10 +32,6 @@ public abstract class BaseProfitBricksResponseHandler extends ParseSax.Handle strBuilder.append(ch, start, length); } - protected final Date textToIso8601Date() { - return dateCodec.toDate(textToStringValue()); - } - protected String textToStringValue() { return strBuilder.toString().trim(); } @@ -52,9 +39,9 @@ public abstract class BaseProfitBricksResponseHandler extends ParseSax.Handle protected Float textToFloatValue() { return Float.valueOf(textToStringValue()); } - - protected Double textToDoubleValue(){ - return Double.valueOf( textToStringValue()); + + protected Double textToDoubleValue() { + return Double.valueOf(textToStringValue()); } protected int textToIntValue() { diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandler.java index 6e6b288ed1..2914e50cc0 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandler.java @@ -16,28 +16,24 @@ */ package org.jclouds.profitbricks.http.parser; -import com.google.inject.Inject; -import org.jclouds.date.DateCodecFactory; import org.xml.sax.SAXException; public class RequestIdOnlyResponseHandler extends BaseProfitBricksResponseHandler { private String requestId; - @Inject - RequestIdOnlyResponseHandler( DateCodecFactory dateCodec ) { - super( dateCodec ); + RequestIdOnlyResponseHandler() { } @Override - public void endElement( String uri, String localName, String qName ) throws SAXException { - setPropertyOnEndTag( qName ); + public void endElement(String uri, String localName, String qName) throws SAXException { + setPropertyOnEndTag(qName); clearTextBuffer(); } @Override - protected void setPropertyOnEndTag( String qName ) { - if ( "requestId".equals( qName ) ) + protected void setPropertyOnEndTag(String qName) { + if ("requestId".equals(qName)) requestId = textToStringValue(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandler.java index c6a504b6f0..f21c32e632 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandler.java @@ -16,42 +16,37 @@ */ package org.jclouds.profitbricks.http.parser; -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.ServiceFault; import org.xml.sax.SAXException; -import com.google.inject.Inject; - public class ServiceFaultResponseHandler extends BaseProfitBricksResponseHandler { private final ServiceFault.Builder builder; private boolean done = false; - @Inject - ServiceFaultResponseHandler(DateCodecFactory dateCodec) { - super(dateCodec); + ServiceFaultResponseHandler() { this.builder = ServiceFault.builder(); } @Override protected void setPropertyOnEndTag(String qName) { if ("faultCode".equals(qName)) - builder.faultCode(ServiceFault.FaultCode.fromValue(textToStringValue())); + builder.faultCode(ServiceFault.FaultCode.fromValue(textToStringValue())); else if ("httpCode".equals(qName)) - builder.httpCode(textToIntValue()); + builder.httpCode(textToIntValue()); else if ("message".equals(qName)) - builder.message(textToStringValue()); + builder.message(textToStringValue()); else if ("requestId".equals(qName)) - builder.requestId(textToIntValue()); + builder.requestId(textToIntValue()); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (done) - return; + return; setPropertyOnEndTag(qName); if ("detail".equals(qName)) - done = true; + done = true; clearTextBuffer(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/BaseDataCenterResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/BaseDataCenterResponseHandler.java index 409131fb80..931d5e97a5 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/BaseDataCenterResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/BaseDataCenterResponseHandler.java @@ -16,9 +16,6 @@ */ package org.jclouds.profitbricks.http.parser.datacenter; -import javax.inject.Inject; - -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.DataCenter; import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; @@ -26,18 +23,16 @@ public abstract class BaseDataCenterResponseHandler extends BaseProfitBricksR protected DataCenter.Builder builder; - @Inject - BaseDataCenterResponseHandler(DateCodecFactory dateCodecFactory) { - super(dateCodecFactory); + BaseDataCenterResponseHandler() { this.builder = DataCenter.builder(); } @Override protected void setPropertyOnEndTag(String qName) { if ("dataCenterId".equals(qName)) - builder.id(textToStringValue()); + builder.id(textToStringValue()); else if ("dataCenterVersion".equals(qName)) - builder.version(textToIntValue()); + builder.version(textToIntValue()); } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandler.java index 5b3aadd599..d44c880bb3 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandler.java @@ -16,42 +16,94 @@ */ package org.jclouds.profitbricks.http.parser.datacenter; -import org.jclouds.date.DateCodecFactory; +import java.util.List; + import org.jclouds.profitbricks.domain.DataCenter; import org.jclouds.profitbricks.domain.Location; import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.profitbricks.http.parser.server.ServerInfoResponseHandler; +import org.jclouds.profitbricks.http.parser.storage.StorageInfoResponseHandler; +import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.Lists; import com.google.inject.Inject; public class DataCenterInfoResponseHandler extends BaseDataCenterResponseHandler { + private final ServerInfoResponseHandler serverInfoResponseHandler; + private final StorageInfoResponseHandler storageInfoResponseHandler; + + private final List servers = Lists.newArrayList(); + private final List storages = Lists.newArrayList(); + private boolean done = false; + private boolean useServerParser = false; + private boolean useStorageParser = false; @Inject - DataCenterInfoResponseHandler(DateCodecFactory dateCodecFactory) { - super(dateCodecFactory); + DataCenterInfoResponseHandler(ServerInfoResponseHandler serverInfoResponseHandler, StorageInfoResponseHandler storageInforResponseHandler) { + this.serverInfoResponseHandler = serverInfoResponseHandler; + this.storageInfoResponseHandler = storageInforResponseHandler; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if ("servers".equals(qName)) + useServerParser = true; + else if ("storages".equals(qName)) + useStorageParser = true; } @Override protected void setPropertyOnEndTag(String qName) { super.setPropertyOnEndTag(qName); if ("dataCenterName".equals(qName)) - builder.name(textToStringValue()); + builder.name(textToStringValue()); else if ("location".equals(qName)) - builder.location(Location.fromId(textToStringValue())); + builder.location(Location.fromId(textToStringValue())); else if ("provisioningState".equals(qName)) - builder.state(ProvisioningState.fromValue(textToStringValue())); + builder.state(ProvisioningState.fromValue(textToStringValue())); + } + + @Override + public void characters(char[] ch, int start, int length) { + if (useServerParser) + serverInfoResponseHandler.characters(ch, start, length); + else if (useStorageParser) + storageInfoResponseHandler.characters(ch, start, length); + else + super.characters(ch, start, length); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (done) - return; - setPropertyOnEndTag(qName); - if ("return".equals(qName)) - done = true; - clearTextBuffer(); + return; + + if ("servers".equals(qName)) { + useServerParser = false; + servers.add(serverInfoResponseHandler.getResult()); + } else if ("storages".equals(qName)) { + useStorageParser = false; + storages.add(storageInfoResponseHandler.getResult()); + } + + if (useServerParser) + serverInfoResponseHandler.endElement(uri, localName, qName); + else if (useStorageParser) + storageInfoResponseHandler.endElement(uri, localName, qName); + else { + setPropertyOnEndTag(qName); + if ("return".equals(qName)) { + done = true; + builder.servers(servers); + builder.storages(storages); + } + clearTextBuffer(); + } } @Override diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandler.java index 8b8ad1a058..b66264ea96 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandler.java @@ -18,22 +18,18 @@ package org.jclouds.profitbricks.http.parser.datacenter; import java.util.List; -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.DataCenter; import org.jclouds.profitbricks.domain.Location; import org.jclouds.profitbricks.domain.ProvisioningState; import org.xml.sax.SAXException; import com.google.common.collect.Lists; -import com.google.inject.Inject; public class DataCenterListResponseHandler extends BaseDataCenterResponseHandler> { private final List dataCenters; - @Inject - DataCenterListResponseHandler(DateCodecFactory dateCodec) { - super(dateCodec); + DataCenterListResponseHandler() { this.dataCenters = Lists.newArrayList(); } @@ -46,19 +42,19 @@ public class DataCenterListResponseHandler extends BaseDataCenterResponseHandler protected void setPropertyOnEndTag(String qName) { super.setPropertyOnEndTag(qName); if ("dataCenterName".equals(qName)) - builder.name(textToStringValue()); + builder.name(textToStringValue()); else if ("location".equals(qName)) - builder.location(Location.fromValue(textToStringValue())); + builder.location(Location.fromValue(textToStringValue())); else if ("provisioningState".equals(qName)) - builder.state(ProvisioningState.fromValue(textToStringValue())); + builder.state(ProvisioningState.fromValue(textToStringValue())); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { setPropertyOnEndTag(qName); if ("return".equals(qName)) { - dataCenters.add(builder.build()); - builder = DataCenter.builder(); + dataCenters.add(builder.build()); + builder = DataCenter.builder(); } clearTextBuffer(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/BaseImageResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/BaseImageResponseHandler.java index 1a6ff94d57..1e8828c96b 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/BaseImageResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/BaseImageResponseHandler.java @@ -16,9 +16,6 @@ */ package org.jclouds.profitbricks.http.parser.image; -import javax.inject.Inject; - -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.Image; import org.jclouds.profitbricks.domain.Image.Type; import org.jclouds.profitbricks.domain.Location; @@ -29,9 +26,7 @@ public abstract class BaseImageResponseHandler extends BaseProfitBricksRespon protected Image.Builder builder; - @Inject - BaseImageResponseHandler(DateCodecFactory dateCodecFactory) { - super(dateCodecFactory); + BaseImageResponseHandler() { this.builder = Image.builder(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandler.java index 0736acb210..62d3973aea 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandler.java @@ -16,8 +16,6 @@ */ package org.jclouds.profitbricks.http.parser.image; -import com.google.inject.Inject; -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.Image; import org.xml.sax.SAXException; @@ -25,9 +23,7 @@ public class ImageInfoResponseHandler extends BaseImageResponseHandler { private boolean done = false; - @Inject - ImageInfoResponseHandler(DateCodecFactory dateCodecFactory) { - super(dateCodecFactory); + ImageInfoResponseHandler() { } @Override diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandler.java index 8fc8091c8a..ee73908220 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandler.java @@ -17,9 +17,9 @@ package org.jclouds.profitbricks.http.parser.image; import com.google.common.collect.Lists; -import com.google.inject.Inject; + import java.util.List; -import org.jclouds.date.DateCodecFactory; + import org.jclouds.profitbricks.domain.Image; import org.xml.sax.SAXException; @@ -27,9 +27,7 @@ public class ImageListResponseHandler extends BaseImageResponseHandler images; - @Inject - ImageListResponseHandler(DateCodecFactory dateCodecFactory) { - super(dateCodecFactory); + ImageListResponseHandler() { this.images = Lists.newArrayList(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java index e594ce47a8..356d2181d4 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java @@ -16,7 +16,12 @@ */ package org.jclouds.profitbricks.http.parser.server; +import java.util.Date; + +import org.jclouds.date.DateCodec; + import com.google.inject.Inject; + import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.AvailabilityZone; import org.jclouds.profitbricks.domain.OsType; @@ -28,48 +33,54 @@ public abstract class BaseServerResponseHandler extends BaseProfitBricksRespo protected Server.DescribingBuilder builder; + protected final DateCodec dateCodec; + @Inject - BaseServerResponseHandler( DateCodecFactory dateCodec ) { - super( dateCodec ); + BaseServerResponseHandler(DateCodecFactory dateCodec) { + this.dateCodec = dateCodec.iso8601(); this.builder = Server.builder(); } + protected final Date textToIso8601Date() { + return dateCodec.toDate(textToStringValue()); + } + @Override - protected void setPropertyOnEndTag( String qName ) { - if ( "serverId".equals( qName ) ) - builder.id( textToStringValue() ); - else if ( "serverName".equals( qName ) ) - builder.name( textToStringValue() ); - else if ( "cores".equals( qName ) ) - builder.cores( textToIntValue() ); - else if ( "ram".equals( qName ) ) - builder.ram( textToIntValue() ); - else if ( "provisioningState".equals( qName ) ) - builder.state( ProvisioningState.fromValue( textToStringValue() ) ); - else if ( "virtualMachineState".equals( qName ) ) - builder.status( Server.Status.fromValue( textToStringValue() ) ); - else if ( "osType".equals( qName ) ) - builder.osType( OsType.fromValue( textToStringValue() ) ); - else if ( "availabilityZone".equals( qName ) ) - builder.availabilityZone( AvailabilityZone.fromValue( textToStringValue() ) ); - else if ( "creationTime".equals( qName ) ) - builder.creationTime( textToIso8601Date() ); - else if ( "lastModificationTime".equals( qName ) ) - builder.lastModificationTime( textToIso8601Date() ); - else if ( "internetAccess".equals( qName ) ) - builder.hasInternetAccess( textToBooleanValue() ); - else if ( "cpuHotPlug".equals( qName ) ) - builder.isCpuHotPlug( textToBooleanValue() ); - else if ( "ramHotPlug".equals( qName ) ) - builder.isRamHotPlug( textToBooleanValue() ); - else if ( "nicHotPlug".equals( qName ) ) - builder.isNicHotPlug( textToBooleanValue() ); - else if ( "nicHotUnPlug".equals( qName ) ) - builder.isNicHotUnPlug( textToBooleanValue() ); - else if ( "discVirtioHotPlug".equals( qName ) ) - builder.isDiscVirtioHotPlug( textToBooleanValue() ); - else if ( "discVirtioHotUnPlug".equals( qName ) ) - builder.isDiscVirtioHotUnPlug( textToBooleanValue() ); + protected void setPropertyOnEndTag(String qName) { + if ("serverId".equals(qName)) + builder.id(textToStringValue()); + else if ("serverName".equals(qName)) + builder.name(textToStringValue()); + else if ("cores".equals(qName)) + builder.cores(textToIntValue()); + else if ("ram".equals(qName)) + builder.ram(textToIntValue()); + else if ("provisioningState".equals(qName)) + builder.state(ProvisioningState.fromValue(textToStringValue())); + else if ("virtualMachineState".equals(qName)) + builder.status(Server.Status.fromValue(textToStringValue())); + else if ("osType".equals(qName)) + builder.osType(OsType.fromValue(textToStringValue())); + else if ("availabilityZone".equals(qName)) + builder.availabilityZone(AvailabilityZone.fromValue(textToStringValue())); + else if ("creationTime".equals(qName)) + builder.creationTime(textToIso8601Date()); + else if ("lastModificationTime".equals(qName)) + builder.lastModificationTime(textToIso8601Date()); + else if ("internetAccess".equals(qName)) + builder.hasInternetAccess(textToBooleanValue()); + else if ("cpuHotPlug".equals(qName)) + builder.isCpuHotPlug(textToBooleanValue()); + else if ("ramHotPlug".equals(qName)) + builder.isRamHotPlug(textToBooleanValue()); + else if ("nicHotPlug".equals(qName)) + builder.isNicHotPlug(textToBooleanValue()); + else if ("nicHotUnPlug".equals(qName)) + builder.isNicHotUnPlug(textToBooleanValue()); + else if ("discVirtioHotPlug".equals(qName)) + builder.isDiscVirtioHotPlug(textToBooleanValue()); + else if ("discVirtioHotUnPlug".equals(qName)) + builder.isDiscVirtioHotUnPlug(textToBooleanValue()); } } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandler.java index ed88018b7b..1c743544c0 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandler.java @@ -16,8 +16,6 @@ */ package org.jclouds.profitbricks.http.parser.server; -import com.google.inject.Inject; -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; import org.xml.sax.SAXException; @@ -30,20 +28,18 @@ public class ServerIdOnlyResponseHandler extends BaseProfitBricksResponseHandler private String serverId; - @Inject - ServerIdOnlyResponseHandler( DateCodecFactory dateCodec ) { - super( dateCodec ); + ServerIdOnlyResponseHandler() { } @Override - public void endElement( String uri, String localName, String qName ) throws SAXException { - setPropertyOnEndTag( qName ); + public void endElement(String uri, String localName, String qName) throws SAXException { + setPropertyOnEndTag(qName); clearTextBuffer(); } @Override - protected void setPropertyOnEndTag( String qName ) { - if ( "serverId".equals( qName ) ) + protected void setPropertyOnEndTag(String qName) { + if ("serverId".equals(qName)) serverId = textToStringValue(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java index dfac4ff9e1..3dc6e6e25f 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java @@ -26,16 +26,16 @@ public class ServerInfoResponseHandler extends BaseServerResponseHandler private boolean done = false; @Inject - ServerInfoResponseHandler( DateCodecFactory dateCodec ) { - super( dateCodec ); + ServerInfoResponseHandler(DateCodecFactory dateCodec) { + super(dateCodec); } @Override - public void endElement( String uri, String localName, String qName ) throws SAXException { - if ( done ) + public void endElement(String uri, String localName, String qName) throws SAXException { + if (done) return; - setPropertyOnEndTag( qName ); - if ( "return".equals( qName ) ) + setPropertyOnEndTag(qName); + if ("return".equals(qName)) done = true; clearTextBuffer(); } diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java index f50027cdff..f0fcd3f76d 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java @@ -28,16 +28,16 @@ public class ServerListResponseHandler extends BaseServerResponseHandler servers; @Inject - ServerListResponseHandler( DateCodecFactory dateCodec ) { - super( dateCodec ); + ServerListResponseHandler(DateCodecFactory dateCodec) { + super(dateCodec); this.servers = Lists.newArrayList(); } @Override - public void endElement( String uri, String localName, String qName ) throws SAXException { - setPropertyOnEndTag( qName ); - if ( "return".equals( qName ) ) { - servers.add( builder.build() ); + public void endElement(String uri, String localName, String qName) throws SAXException { + setPropertyOnEndTag(qName); + if ("return".equals(qName)) { + servers.add(builder.build()); builder = Server.builder(); } clearTextBuffer(); diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandler.java index 705a9180a6..d618cc1dca 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandler.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandler.java @@ -16,20 +16,15 @@ */ package org.jclouds.profitbricks.http.parser.state; -import org.jclouds.date.DateCodecFactory; import org.jclouds.profitbricks.domain.ProvisioningState; import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; import org.xml.sax.SAXException; -import com.google.inject.Inject; - public class GetProvisioningStateResponseHandler extends BaseProfitBricksResponseHandler { private ProvisioningState state = ProvisioningState.UNRECOGNIZED; - @Inject - GetProvisioningStateResponseHandler(DateCodecFactory dateCodec) { - super(dateCodec); + GetProvisioningStateResponseHandler() { } @Override @@ -41,7 +36,7 @@ public class GetProvisioningStateResponseHandler extends BaseProfitBricksRespons @Override protected void setPropertyOnEndTag(String qName) { if ("return".equals(qName)) - state = ProvisioningState.fromValue(textToStringValue()); + state = ProvisioningState.fromValue(textToStringValue()); } @Override diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/BaseStorageResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/BaseStorageResponseHandler.java new file mode 100644 index 0000000000..cb61e79ee2 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/BaseStorageResponseHandler.java @@ -0,0 +1,83 @@ +/* + * 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.profitbricks.http.parser.storage; + +import java.util.Date; +import java.util.List; + +import org.jclouds.date.DateCodec; + +import com.google.inject.Inject; + +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.profitbricks.domain.Storage.BusType; +import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; + +import com.google.common.collect.Lists; + +public abstract class BaseStorageResponseHandler extends BaseProfitBricksResponseHandler { + + protected final DateCodec dateCodec; + + protected Storage.Builder builder; + protected List serverIds; + + @Inject + BaseStorageResponseHandler(DateCodecFactory dateCodec) { + this.dateCodec = dateCodec.iso8601(); + this.builder = Storage.builder(); + this.serverIds = Lists.newArrayList(); + } + + protected final Date textToIso8601Date() { + return dateCodec.toDate(textToStringValue()); + } + + @Override + protected void setPropertyOnEndTag(String qName) { +// ? +// ? +// ? + if ("storageId".equals(qName)) + builder.id(textToStringValue()); + else if ("size".equals(qName)) + builder.size(textToFloatValue()); + else if ("storageName".equals(qName)) + builder.name(textToStringValue()); + else if ("provisioningState".equals(qName)) + builder.state(ProvisioningState.fromValue(textToStringValue())); + else if ("creationTime".equals(qName)) + builder.creationTime(textToIso8601Date()); + else if ("lastModificationTime".equals(qName)) + builder.lastModificationTime(textToIso8601Date()); +// +// ? +// ? +// + else if ("serverIds".equals(qName)) + serverIds.add(textToStringValue()); + else if ("bootDevice".equals(qName)) + builder.bootDevice(textToBooleanValue()); + else if ("busType".equals(qName)) + builder.busType(BusType.fromValue(textToStringValue())); + else if ("deviceNumber".equals(qName)) + builder.deviceNumber(textToIntValue()); + } + +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandler.java new file mode 100644 index 0000000000..ac3a039d9d --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandler.java @@ -0,0 +1,46 @@ +/* + * 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.profitbricks.http.parser.storage; + +import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; +import org.xml.sax.SAXException; + +public class StorageIdOnlyResponseHandler extends BaseProfitBricksResponseHandler { + + private String storageId; + + StorageIdOnlyResponseHandler() { + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + setPropertyOnEndTag(qName); + clearTextBuffer(); + } + + @Override + protected void setPropertyOnEndTag(String qName) { + if ("storageId".equals(qName)) + storageId = textToStringValue(); + } + + @Override + public String getResult() { + return storageId; + } + +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandler.java new file mode 100644 index 0000000000..2bc1ed6701 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandler.java @@ -0,0 +1,50 @@ +/* + * 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.profitbricks.http.parser.storage; + +import com.google.inject.Inject; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Storage; +import org.xml.sax.SAXException; + +public class StorageInfoResponseHandler extends BaseStorageResponseHandler { + + private boolean done = false; + + @Inject + StorageInfoResponseHandler(DateCodecFactory dateCodec) { + super(dateCodec); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (done) + return; + setPropertyOnEndTag(qName); + if ("return".equals(qName)) { + done = true; + builder.serverIds(serverIds); + } + clearTextBuffer(); + } + + @Override + public Storage getResult() { + return builder.build(); + } + +} diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java new file mode 100644 index 0000000000..fe5e3fafc9 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandler.java @@ -0,0 +1,54 @@ +/* + * 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.profitbricks.http.parser.storage; + +import autovalue.shaded.com.google.common.common.collect.Lists; +import com.google.inject.Inject; +import java.util.List; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Storage; +import org.xml.sax.SAXException; + +public class StorageListResponseHandler extends BaseStorageResponseHandler> { + + private final List storages; + + @Inject + StorageListResponseHandler(DateCodecFactory dateCodec) { + super(dateCodec); + this.storages = Lists.newArrayList(); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + setPropertyOnEndTag(qName); + if ("return".equals(qName)) { + storages.add(builder + .serverIds(serverIds) + .build()); + builder = Storage.builder(); + serverIds = Lists.newArrayList(); + } + clearTextBuffer(); + } + + @Override + public List getResult() { + return storages; + } + +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/BaseProfitBricksLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/BaseProfitBricksLiveTest.java index 3ebc9c0d99..e310b6e207 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/BaseProfitBricksLiveTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/BaseProfitBricksLiveTest.java @@ -38,8 +38,8 @@ public abstract class BaseProfitBricksLiveTest extends BaseApiLiveTest\n" - + " \n" - + " JClouds-DC\n" - + " de/fkb\n" - + " \n" - + " \n").replaceAll("\\s+", ""); + = (" \n" + + " \n" + + " JClouds-DC\n" + + " de/fkb\n" + + " \n" + + " \n").replaceAll("\\s+", ""); } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java index 9e72172bfa..3f989ce592 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java @@ -37,10 +37,10 @@ public class UpdateDataCenterRequestBinderTest { } private final String expectedPayload - = (" \n" - + " \n" - + " aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\n" - + " Apache-DC\n" - + " \n" - + " ").replaceAll("\\s+", ""); + = (" \n" + + " \n" + + " aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\n" + + " Apache-DC\n" + + " \n" + + " ").replaceAll("\\s+", ""); } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinderTest.java index bf18841245..355f318a26 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinderTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinderTest.java @@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "CreateServerRequestBinderTest" ) +@Test(groups = "unit", testName = "CreateServerRequestBinderTest") public class CreateServerRequestBinderTest { @Test @@ -29,37 +29,37 @@ public class CreateServerRequestBinderTest { CreateServerRequestBinder binder = new CreateServerRequestBinder(); Server.Request.CreatePayload payload = Server.Request.creatingBuilder() - .name( "jclouds-node" ) - .cores( 4 ) - .ram( 4 * 1024 ) - .dataCenterId( "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ) + .name("jclouds-node") + .cores(4) + .ram(4 * 1024) + .dataCenterId("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") .build(); - String actual = binder.createPayload( payload ); - assertNotNull( actual, "Binder returned null payload" ); - assertEquals( actual, expectedPayload ); + String actual = binder.createPayload(payload); + assertNotNull(actual, "Binder returned null payload"); + assertEquals(actual, expectedPayload); } private final String expectedPayload - = ( " \n" + = (" \n" + " \n" + " aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\n" + " 4\n" + " 4096\n" + " jclouds-node\n" -// + " ?\n" -// + " ?\n" -// + " false\n" -// + " ?\n" -// + " ?\n" -// + " AUTO\n" -// + " false\n" -// + " false\n" -// + " false\n" -// + " false\n" -// + " false\n" -// + " false\n" + // + " ?\n" + // + " ?\n" + // + " false\n" + // + " ?\n" + // + " ?\n" + // + " AUTO\n" + // + " false\n" + // + " false\n" + // + " false\n" + // + " false\n" + // + " false\n" + // + " false\n" + " \n" - + " " ) - .replaceAll( "\\s+", "" ); + + " ") + .replaceAll("\\s+", ""); } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinderTest.java index cba666bf10..aa0e31c17f 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinderTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinderTest.java @@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "UpdateServerRequestBinderTest" ) +@Test(groups = "unit", testName = "UpdateServerRequestBinderTest") public class UpdateServerRequestBinderTest { @Test @@ -29,36 +29,36 @@ public class UpdateServerRequestBinderTest { UpdateServerRequestBinder binder = new UpdateServerRequestBinder(); Server.Request.UpdatePayload payload = Server.Request.updatingBuilder() - .id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" ) - .cores( 8 ) - .ram( 8 * 1024 ) - .name( "apache-node") + .id("qwertyui-qwer-qwer-qwer-qwertyyuiiop") + .cores(8) + .ram(8 * 1024) + .name("apache-node") .build(); - - String actual = binder.createPayload( payload ); + + String actual = binder.createPayload(payload); assertNotNull(actual, "Binder returned null payload"); assertEquals(actual, expectedPayload); } private final String expectedPayload - = ( " \n" + = (" \n" + " \n" + " qwertyui-qwer-qwer-qwer-qwertyyuiiop\n" + " 8\n" + " 8192\n" + " apache-node\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" -// + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + // + " ?\n" + " \n" - + " " ) - .replaceAll( "\\s+", "" ); + + " ") + .replaceAll("\\s+", ""); } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinderTest.java new file mode 100644 index 0000000000..0c0d3a496d --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/ConnectStorageToServerRequestBinderTest.java @@ -0,0 +1,55 @@ +/* + * 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.profitbricks.binder.storage; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.profitbricks.domain.Storage; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "ConnectStorageToServerRequestBinderTest") +public class ConnectStorageToServerRequestBinderTest { + + @Test + public void testCreatePayload() { + ConnectStorageToServerRequestBinder binder = new ConnectStorageToServerRequestBinder(); + + Storage.Request.ConnectPayload payload = Storage.Request.connectingBuilder() + .serverId("qwertyui-qwer-qwer-qwer-qwertyyuiiop") + .storageId("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") + .busType(Storage.BusType.VIRTIO) + .deviceNumber(2) + .build(); + + String actual = binder.createPayload(payload); + assertNotNull(actual, "Binder returned null payload"); + assertEquals(actual, expectedPayload); + } + + private final String expectedPayload + = (" \n" + + " \n" + + " qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh\n" + + " qwertyui-qwer-qwer-qwer-qwertyyuiiop\n" + + " VIRTIO\n" + + " 2\n" + + " \n" + + " ") + .replaceAll("\\s+", ""); + +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinderTest.java new file mode 100644 index 0000000000..9120be7a61 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/CreateStorageRequestBinderTest.java @@ -0,0 +1,56 @@ +/* + * 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.profitbricks.binder.storage; + +import org.jclouds.profitbricks.domain.Storage; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "CreateStorageRequestBinderTest") +public class CreateStorageRequestBinderTest { + + @Test + public void testCreatePayload() { + CreateStorageRequestBinder binder = new CreateStorageRequestBinder(); + + Storage.Request.CreatePayload payload = Storage.Request.creatingBuilder() + .name("hdd-1") + .size(60f) + .dataCenterId("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .mountImageId("5ad99c9e-9166-11e4-9d74-52540066fee9") + .imagePassword("qqqqqqqqq") + .build(); + + String actual = binder.createPayload(payload); + assertNotNull(actual, "Binder returned null payload"); + assertEquals(actual, expectedPayload); + } + + private final String expectedPayload + = (" \n" + + " \n" + + " aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\n" + + " hdd-1\n" + + " 60\n" + + " 5ad99c9e-9166-11e4-9d74-52540066fee9\n" + + " qqqqqqqqq\n" + + " \n" + + " ") + .replaceAll("\\s+", ""); + +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinderTest.java new file mode 100644 index 0000000000..0240297d0e --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/storage/UpdateStorageRequestBinderTest.java @@ -0,0 +1,53 @@ +/* + * 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.profitbricks.binder.storage; + +import org.jclouds.profitbricks.domain.Storage; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "UpdateStorageRequestBinderTest") +public class UpdateStorageRequestBinderTest { + + @Test + public void testUpdatePayload() { + UpdateStorageRequestBinder binder = new UpdateStorageRequestBinder(); + + Storage.Request.UpdatePayload payload = Storage.Request.updatingBuilder() + .id("pppppppp-llkl-kkjk-fhgh-vnmegrdgdsgr") + .size(100f) + .name("hdd-2") + .mountImageId("5f3cac96-915f-11e4-9d74-52540066fee9") + .build(); + + String actual = binder.createPayload(payload); + assertNotNull(actual, "Binder returned null payload"); + assertEquals(actual, expectedPayload); + } + + private final String expectedPayload + = (" \n" + + " \n" + + " pppppppp-llkl-kkjk-fhgh-vnmegrdgdsgr\n" + + " 100\n" + + " hdd-2\n" + + " 5f3cac96-915f-11e4-9d74-52540066fee9\n" + + " \n" + + " ") + .replaceAll("\\s+", ""); +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java index 05001f2b0e..f69fc02fbb 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java @@ -39,7 +39,7 @@ import com.squareup.okhttp.mockwebserver.MockWebServer; public class ProvisioningStatusPollingPredicateTest extends BaseProfitBricksMockTest { @Test - public void testPredicate() throws Exception { + public void testDataCenterPredicate() throws Exception { MockWebServer server = mockWebServer(); byte[] payloadInProcess = payloadFromResource("/datacenter/datacenter-state-inprocess.xml"); @@ -71,4 +71,70 @@ public class ProvisioningStatusPollingPredicateTest extends BaseProfitBricksMock } } + @Test + public void testServerPredicate() throws Exception { + MockWebServer server = mockWebServer(); + + byte[] payloadInProcess = payloadFromResource("/server/server-state-inprocess.xml"); + byte[] payloadAvailable = payloadFromResource("/server/server.xml"); + + // wait 3 times + server.enqueue(new MockResponse().setBody(payloadInProcess)); + server.enqueue(new MockResponse().setBody(payloadInProcess)); + server.enqueue(new MockResponse().setBody(payloadInProcess)); + server.enqueue(new MockResponse().setBody(payloadAvailable)); + + server.enqueue(new MockResponse().setBody(payloadAvailable)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + + Predicate waitUntilAvailable = Predicates2.retry( + new ProvisioningStatusPollingPredicate(pbApi, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE), + 30l, 1l, TimeUnit.SECONDS); + + String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; + try { + waitUntilAvailable.apply(id); + ProvisioningState finalState = pbApi.serverApi().getServer(id).state(); + assertRequestHasCommonProperties(server.takeRequest()); + assertEquals(finalState, ProvisioningState.AVAILABLE); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testStoragePredicate() throws Exception { + MockWebServer server = mockWebServer(); + + byte[] payloadInProcess = payloadFromResource("/storage/storage-state-inprocess.xml"); + byte[] payloadAvailable = payloadFromResource("/storage/storage.xml"); + + // wait 3 times + server.enqueue(new MockResponse().setBody(payloadInProcess)); + server.enqueue(new MockResponse().setBody(payloadInProcess)); + server.enqueue(new MockResponse().setBody(payloadInProcess)); + server.enqueue(new MockResponse().setBody(payloadAvailable)); + + server.enqueue(new MockResponse().setBody(payloadAvailable)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + + Predicate waitUntilAvailable = Predicates2.retry( + new ProvisioningStatusPollingPredicate(pbApi, ProvisioningStatusAware.STORAGE, ProvisioningState.AVAILABLE), + 30l, 1l, TimeUnit.SECONDS); + + String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; + try { + waitUntilAvailable.apply(id); + ProvisioningState finalState = pbApi.storageApi().getStorage(id).state(); + assertRequestHasCommonProperties(server.takeRequest()); + assertEquals(finalState, ProvisioningState.AVAILABLE); + } finally { + pbApi.close(); + server.shutdown(); + } + } + } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java index f5f7a20ad5..c04f65cec7 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java @@ -20,7 +20,7 @@ import java.util.Date; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ServerBuilderTest" ) +@Test(groups = "unit", testName = "ServerBuilderTest") public class ServerBuilderTest { private final Boolean _isCpuHotPlug = true; @@ -46,119 +46,117 @@ public class ServerBuilderTest { private final String _bootFromStorageId = "some-random-storage-id"; private final String _bootFromImageId = "some-random-image-id"; - private final String _serverId = "some-random-server-id"; - @Test public void testAutoValueServerPropertiesSettingCorrectly() { Server actual = Server.builder() - .availabilityZone( _availabilityZone ) - .creationTime( _creationTime ) - .cores( _cores ) - .hasInternetAccess( _hasInternetAccess ) - .id( _id ) - .name( _name ) - .isCpuHotPlug( _isCpuHotPlug ) - .isDiscVirtioHotPlug( _isDiscVirtioHotPlug ) - .isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug ) - .isNicHotPlug( _isNicHotPlug ) - .isNicHotUnPlug( _isNicHotUnPlug ) - .isRamHotPlug( _isRamHotPlug ) - .lastModificationTime( _lastModificationTime ) - .ram( _ram ) - .osType( _osType ) - .state( _state ) - .status( _status ) + .availabilityZone(_availabilityZone) + .creationTime(_creationTime) + .cores(_cores) + .hasInternetAccess(_hasInternetAccess) + .id(_id) + .name(_name) + .isCpuHotPlug(_isCpuHotPlug) + .isDiscVirtioHotPlug(_isDiscVirtioHotPlug) + .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug) + .isNicHotPlug(_isNicHotPlug) + .isNicHotUnPlug(_isNicHotUnPlug) + .isRamHotPlug(_isRamHotPlug) + .lastModificationTime(_lastModificationTime) + .ram(_ram) + .osType(_osType) + .state(_state) + .status(_status) .build(); - assertEquals( actual.availabilityZone(), _availabilityZone ); - assertEquals( actual.cores(), _cores ); - assertEquals( actual.creationTime(), _creationTime ); - assertEquals( actual.hasInternetAccess(), _hasInternetAccess ); - assertEquals( actual.id(), _id ); - assertEquals( actual.name(), _name ); - assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug ); - assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug ); - assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug ); - assertEquals( actual.isNicHotPlug(), _isNicHotPlug ); - assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug ); - assertEquals( actual.isRamHotPlug(), _isRamHotPlug ); - assertEquals( actual.lastModificationTime(), _lastModificationTime ); - assertEquals( actual.ram(), _ram ); - assertEquals( actual.osType(), _osType ); - assertEquals( actual.state(), _state ); + assertEquals(actual.availabilityZone(), _availabilityZone); + assertEquals(actual.cores(), _cores); + assertEquals(actual.creationTime(), _creationTime); + assertEquals(actual.hasInternetAccess(), _hasInternetAccess); + assertEquals(actual.id(), _id); + assertEquals(actual.name(), _name); + assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug); + assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug); + assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug); + assertEquals(actual.isNicHotPlug(), _isNicHotPlug); + assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug); + assertEquals(actual.isRamHotPlug(), _isRamHotPlug); + assertEquals(actual.lastModificationTime(), _lastModificationTime); + assertEquals(actual.ram(), _ram); + assertEquals(actual.osType(), _osType); + assertEquals(actual.state(), _state); } @Test public void testAutoValueServerRequestCreatePayloadPropertiesSettingCorrectly() { Server.Request.CreatePayload actual = Server.Request.creatingBuilder() - .availabilityZone( _availabilityZone ) - .bootFromImageId( _bootFromImageId ) - .bootFromStorageId( _bootFromStorageId ) - .cores( _cores ) - .dataCenterId( _dataCenterId ) - .hasInternetAccess( _hasInternetAccess ) - .name( _name ) - .isCpuHotPlug( _isCpuHotPlug ) - .isDiscVirtioHotPlug( _isDiscVirtioHotPlug ) - .isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug ) - .isNicHotPlug( _isNicHotPlug ) - .isNicHotUnPlug( _isNicHotUnPlug ) - .isRamHotPlug( _isRamHotPlug ) - .lanId( _lanId ) - .ram( _ram ) - .osType( _osType ) + .availabilityZone(_availabilityZone) + .bootFromImageId(_bootFromImageId) + .bootFromStorageId(_bootFromStorageId) + .cores(_cores) + .dataCenterId(_dataCenterId) + .hasInternetAccess(_hasInternetAccess) + .name(_name) + .isCpuHotPlug(_isCpuHotPlug) + .isDiscVirtioHotPlug(_isDiscVirtioHotPlug) + .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug) + .isNicHotPlug(_isNicHotPlug) + .isNicHotUnPlug(_isNicHotUnPlug) + .isRamHotPlug(_isRamHotPlug) + .lanId(_lanId) + .ram(_ram) + .osType(_osType) .build(); - assertEquals( actual.availabilityZone(), _availabilityZone ); - assertEquals( actual.bootFromImageId(), _bootFromImageId ); - assertEquals( actual.bootFromStorageId(), _bootFromStorageId ); - assertEquals( actual.cores(), _cores ); - assertEquals( actual.dataCenterId(), _dataCenterId ); - assertEquals( actual.hasInternetAccess(), _hasInternetAccess ); - assertEquals( actual.name(), _name ); - assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug ); - assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug ); - assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug ); - assertEquals( actual.isNicHotPlug(), _isNicHotPlug ); - assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug ); - assertEquals( actual.isRamHotPlug(), _isRamHotPlug ); - assertEquals( actual.lanId(), _lanId ); - assertEquals( actual.ram(), _ram ); - assertEquals( actual.osType(), _osType ); + assertEquals(actual.availabilityZone(), _availabilityZone); + assertEquals(actual.bootFromImageId(), _bootFromImageId); + assertEquals(actual.bootFromStorageId(), _bootFromStorageId); + assertEquals(actual.cores(), _cores); + assertEquals(actual.dataCenterId(), _dataCenterId); + assertEquals(actual.hasInternetAccess(), _hasInternetAccess); + assertEquals(actual.name(), _name); + assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug); + assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug); + assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug); + assertEquals(actual.isNicHotPlug(), _isNicHotPlug); + assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug); + assertEquals(actual.isRamHotPlug(), _isRamHotPlug); + assertEquals(actual.lanId(), _lanId); + assertEquals(actual.ram(), _ram); + assertEquals(actual.osType(), _osType); } @Test public void testAutoValueServerRequestUpdatePayloadPropertiesSettingCorrectly() { Server.Request.UpdatePayload actual = Server.Request.updatingBuilder() - .availabilityZone( _availabilityZone ) - .bootFromImageId( _bootFromImageId ) - .bootFromStorageId( _bootFromStorageId ) - .cores( _cores ) - .name( _name ) - .id( _id ) - .isCpuHotPlug( _isCpuHotPlug ) - .isDiscVirtioHotPlug( _isDiscVirtioHotPlug ) - .isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug ) - .isNicHotPlug( _isNicHotPlug ) - .isNicHotUnPlug( _isNicHotUnPlug ) - .isRamHotPlug( _isRamHotPlug ) - .ram( _ram ) - .osType( _osType ) + .availabilityZone(_availabilityZone) + .bootFromImageId(_bootFromImageId) + .bootFromStorageId(_bootFromStorageId) + .cores(_cores) + .name(_name) + .id(_id) + .isCpuHotPlug(_isCpuHotPlug) + .isDiscVirtioHotPlug(_isDiscVirtioHotPlug) + .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug) + .isNicHotPlug(_isNicHotPlug) + .isNicHotUnPlug(_isNicHotUnPlug) + .isRamHotPlug(_isRamHotPlug) + .ram(_ram) + .osType(_osType) .build(); - assertEquals( actual.availabilityZone(), _availabilityZone ); - assertEquals( actual.bootFromImageId(), _bootFromImageId ); - assertEquals( actual.bootFromStorageId(), _bootFromStorageId ); - assertEquals( actual.cores(), _cores ); - assertEquals( actual.name(), _name ); - assertEquals( actual.id(), _id ); - assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug ); - assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug ); - assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug ); - assertEquals( actual.isNicHotPlug(), _isNicHotPlug ); - assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug ); - assertEquals( actual.isRamHotPlug(), _isRamHotPlug ); - assertEquals( actual.ram(), _ram ); - assertEquals( actual.osType(), _osType ); + assertEquals(actual.availabilityZone(), _availabilityZone); + assertEquals(actual.bootFromImageId(), _bootFromImageId); + assertEquals(actual.bootFromStorageId(), _bootFromStorageId); + assertEquals(actual.cores(), _cores); + assertEquals(actual.name(), _name); + assertEquals(actual.id(), _id); + assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug); + assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug); + assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug); + assertEquals(actual.isNicHotPlug(), _isNicHotPlug); + assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug); + assertEquals(actual.isRamHotPlug(), _isRamHotPlug); + assertEquals(actual.ram(), _ram); + assertEquals(actual.osType(), _osType); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java index 5c05e4dc19..586487bea2 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java @@ -90,7 +90,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { String content = "" + id + ""; try { DataCenter dataCenter = api.getDataCenter(id); - assertRequestHasCommonProperties(server.takeRequest(), content ); + assertRequestHasCommonProperties(server.takeRequest(), content); assertNotNull(dataCenter); assertEquals(dataCenter.id(), id); } finally { @@ -130,7 +130,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { String content = "" + id + ""; try { ProvisioningState state = api.getDataCenterState(id); - assertRequestHasCommonProperties(server.takeRequest(), content ); + assertRequestHasCommonProperties(server.takeRequest(), content); assertNotNull(state); assertEquals(state, ProvisioningState.AVAILABLE); } finally { @@ -155,7 +155,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { DataCenter dataCenter = api.createDataCenter( DataCenter.Request.CreatePayload.create("JClouds-DC", Location.DE_FRA) ); - assertRequestHasCommonProperties(server.takeRequest(), content ); + assertRequestHasCommonProperties(server.takeRequest(), content); assertNotNull(dataCenter); assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); assertEquals(dataCenter.version(), 1); @@ -168,14 +168,13 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { @Test public void testCreateDataCenterWithIllegalArguments() throws Exception { String[] names = {"JCl@ouds", "JC|ouds", "^clouds", ""}; - for (String name : names) { + for (String name : names) try { DataCenter.Request.CreatePayload.create(name, Location.US_LAS); fail("Should have failed for name: ".concat(name)); } catch (IllegalArgumentException ex) { // expected exception } - } } @Test @@ -185,10 +184,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); DataCenterApi api = pbApi.dataCenterApi(); - + String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; String newName = "Apache"; - + String content = "" + "" + id + "" + "" + newName + "" @@ -216,7 +215,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - + String content = "" + id + ""; try { DataCenter dataCenter = api.clearDataCenter(id); @@ -240,7 +239,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - + String content = "" + id + ""; try { boolean result = api.deleteDataCenter(id); @@ -255,7 +254,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { @Test public void testDeleteNonExistingDataCenter() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode( 404 )); + server.enqueue(new MockResponse().setResponseCode(404)); ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); DataCenterApi api = pbApi.dataCenterApi(); diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java index f1229ae176..6e97541879 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java @@ -81,7 +81,7 @@ public class ImageApiMockTest extends BaseProfitBricksMockTest { ImageApi api = pbApi.imageApi(); String id = "5ad99c9e-9166-11e4-9d74-52540066fee9"; - + String content = "" + id + ""; try { Image image = api.getImage(id); diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java index 3237e9c3e5..e7b1b9ce36 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java @@ -34,7 +34,7 @@ import static org.testng.Assert.assertTrue; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; -@Test( groups = "live", testName = "ServerApiLiveTest", singleThreaded = true ) +@Test(groups = "live", testName = "ServerApiLiveTest", singleThreaded = true) public class ServerApiLiveTest extends BaseProfitBricksLiveTest { private Predicate waitUntilAvailable; @@ -45,94 +45,94 @@ public class ServerApiLiveTest extends BaseProfitBricksLiveTest { protected void initialize() { super.initialize(); List dataCenters = api.dataCenterApi().getAllDataCenters(); - assertFalse( dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing." ); + assertFalse(dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing."); - this.dataCenter = Iterables.getFirst( dataCenters, null ); + this.dataCenter = Iterables.getFirst(dataCenters, null); this.waitUntilAvailable = Predicates2.retry( - new ProvisioningStatusPollingPredicate( api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE ), - 2l * 60l, 2l, TimeUnit.SECONDS ); + new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE), + 2l * 60l, 2l, TimeUnit.SECONDS); } @Test public void testCreateServer() { String serverId = api.serverApi().createServer( - Server.Request.CreatePayload.create( dataCenter.id(), "jclouds-node", 1, 1024 ) ); + Server.Request.CreatePayload.create(dataCenter.id(), "jclouds-node", 1, 1024)); - assertNotNull( serverId ); + assertNotNull(serverId); this.createdServerId = serverId; } - @Test( dependsOnMethods = "testCreateServer" ) + @Test(dependsOnMethods = "testCreateServer") public void testGetServer() { - Server server = api.serverApi().getServer( createdServerId ); + Server server = api.serverApi().getServer(createdServerId); - assertNotNull( server ); - assertEquals( server.id(), createdServerId ); + assertNotNull(server); + assertEquals(server.id(), createdServerId); } - @Test( dependsOnMethods = "testCreateServer" ) + @Test(dependsOnMethods = "testCreateServer") public void testGetAllServers() { List servers = api.serverApi().getAllServers(); - assertNotNull( servers ); - assertFalse( servers.isEmpty() ); + assertNotNull(servers); + assertFalse(servers.isEmpty()); } - @Test( dependsOnMethods = "testCreateServer" ) + @Test(dependsOnMethods = "testCreateServer") public void testWaitUntilAvailable() { - boolean available = waitUntilAvailable.apply( createdServerId ); + boolean available = waitUntilAvailable.apply(createdServerId); - assertTrue( available ); + assertTrue(available); } - @Test( dependsOnMethods = "testWaitUntilAvailable" ) + @Test(dependsOnMethods = "testWaitUntilAvailable") public void testUpdateServer() { String requestId = api.serverApi().updateServer( Server.Request.updatingBuilder() - .id( createdServerId ) - .name( "apache-node" ) - .cores( 2 ) - .ram( 2 * 1024 ) - .build() ); + .id(createdServerId) + .name("apache-node") + .cores(2) + .ram(2 * 1024) + .build()); - assertNotNull( requestId ); - waitUntilAvailable.apply( createdServerId ); + assertNotNull(requestId); + waitUntilAvailable.apply(createdServerId); - Server server = api.serverApi().getServer( createdServerId ); - assertEquals( server.state(), ProvisioningState.AVAILABLE ); + Server server = api.serverApi().getServer(createdServerId); + assertEquals(server.state(), ProvisioningState.AVAILABLE); } - @Test( dependsOnMethods = "testUpdateServer" ) + @Test(dependsOnMethods = "testUpdateServer") public void testStopServer() { - String requestId = api.serverApi().stopServer( createdServerId ); - assertNotNull( requestId ); + String requestId = api.serverApi().stopServer(createdServerId); + assertNotNull(requestId); - Predicate waitUntilInactive = Predicates2.retry( new ProvisioningStatusPollingPredicate( - api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE ), 2l * 60l, 2l, TimeUnit.SECONDS ); + Predicate waitUntilInactive = Predicates2.retry(new ProvisioningStatusPollingPredicate( + api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE), 2l * 60l, 2l, TimeUnit.SECONDS); - waitUntilInactive.apply( createdServerId ); - Server server = api.serverApi().getServer( createdServerId ); - assertEquals( server.status(), Server.Status.SHUTOFF ); + waitUntilInactive.apply(createdServerId); + Server server = api.serverApi().getServer(createdServerId); + assertEquals(server.status(), Server.Status.SHUTOFF); } - @Test( dependsOnMethods = "testStopServer" ) + @Test(dependsOnMethods = "testStopServer") public void testStartServer() { - String requestId = api.serverApi().startServer( createdServerId ); - assertNotNull( requestId ); + String requestId = api.serverApi().startServer(createdServerId); + assertNotNull(requestId); - waitUntilAvailable.apply( createdServerId ); + waitUntilAvailable.apply(createdServerId); - Server server = api.serverApi().getServer( createdServerId ); - assertEquals( server.status(), Server.Status.RUNNING ); + Server server = api.serverApi().getServer(createdServerId); + assertEquals(server.status(), Server.Status.RUNNING); } - @AfterClass( alwaysRun = true ) + @AfterClass(alwaysRun = true) public void testDeleteServer() { - if ( createdServerId != null ) { - boolean result = api.serverApi().deleteServer( createdServerId ); + if (createdServerId != null) { + boolean result = api.serverApi().deleteServer(createdServerId); - assertTrue( result, "Created test server was not deleted." ); + assertTrue(result, "Created test server was not deleted."); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java index d9fd478c9e..47738b81bc 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java @@ -16,39 +16,45 @@ */ package org.jclouds.profitbricks.features; +import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; + import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; + import java.util.List; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.AvailabilityZone; import org.jclouds.profitbricks.domain.OsType; import org.jclouds.profitbricks.domain.Server; import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; import org.jclouds.rest.ResourceNotFoundException; + import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; + import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ServerApiMockTest" ) +@Test(groups = "unit", testName = "ServerApiMockTest") public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testGetAllServers() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/servers.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/servers.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); try { List servers = api.getAllServers(); - assertRequestHasCommonProperties( server.takeRequest(), "" ); - assertNotNull( servers ); - assertTrue( servers.size() == 2 ); + assertRequestHasCommonProperties(server.takeRequest(), ""); + assertNotNull(servers); + assertTrue(servers.size() == 2); } finally { pbApi.close(); server.shutdown(); @@ -58,15 +64,15 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testGetAllServersReturning404() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setResponseCode( 404 ) ); + server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); try { List servers = api.getAllServers(); - assertRequestHasCommonProperties( server.takeRequest() ); - assertTrue( servers.isEmpty() ); + assertRequestHasCommonProperties(server.takeRequest()); + assertTrue(servers.isEmpty()); } finally { pbApi.close(); server.shutdown(); @@ -76,19 +82,19 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testGetServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; String content = "" + id + ""; try { - Server svr = api.getServer( id ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertNotNull( svr ); - assertEquals( svr.id(), id ); + Server svr = api.getServer(id); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(svr); + assertEquals(svr.id(), id); } finally { pbApi.close(); server.shutdown(); @@ -98,16 +104,16 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testGetNonExistingServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setResponseCode( 404 ) ); + server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String id = "random-non-existing-id"; try { - Server srvr = api.getServer( id ); - assertRequestHasCommonProperties( server.takeRequest() ); - assertNull( srvr ); + Server srvr = api.getServer(id); + assertRequestHasCommonProperties(server.takeRequest()); + assertNull(srvr); } finally { pbApi.close(); @@ -118,18 +124,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testStartServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-start.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-start.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; String content = "" + id + ""; try { - String requestId = api.startServer( id ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertEquals( requestId, "123456" ); + String requestId = api.startServer(id); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertEquals(requestId, "123456"); } finally { pbApi.close(); server.shutdown(); @@ -139,17 +145,17 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testStartNonExistingServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setResponseCode( 500 ).setBody( payloadFromResource( "/fault-404.xml" ) ) ); + server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String id = "random-non-existing-id"; try { - String requestId = api.startServer( id ); - assertRequestHasCommonProperties( server.takeRequest() ); - fail( "Should've failed." ); - } catch ( ResourceNotFoundException ex ) { + String requestId = api.startServer(id); + assertRequestHasCommonProperties(server.takeRequest()); + fail("Should've failed."); + } catch (ResourceNotFoundException ex) { // expected exception } finally { pbApi.close(); @@ -160,18 +166,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testStopServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-stop.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-stop.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; String content = "" + id + ""; try { - String requestId = api.stopServer( id ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertEquals( requestId, "123456" ); + String requestId = api.stopServer(id); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertEquals(requestId, "123456"); } finally { pbApi.close(); server.shutdown(); @@ -181,18 +187,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testResetServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-reset.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-reset.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; String content = "" + id + ""; try { - String requestId = api.resetServer( id ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertEquals( requestId, "123456" ); + String requestId = api.resetServer(id); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertEquals(requestId, "123456"); } finally { pbApi.close(); server.shutdown(); @@ -202,9 +208,9 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testCreateServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-create.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-create.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -233,26 +239,26 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { + ""; try { - String serverId = api.createServer( Server.Request.creatingBuilder() - .dataCenterId( dataCenterId ) - .name( name ) - .cores( 4 ) - .ram( 4 * 1024 ) - .bootFromImageId( imageId ) - .hasInternetAccess( Boolean.TRUE ) - .lanId( 2 ) - .osType( OsType.LINUX ) - .availabilityZone( AvailabilityZone.ZONE_1 ) - .isCpuHotPlug( Boolean.TRUE ) - .isRamHotPlug( Boolean.FALSE ) - .isNicHotPlug( Boolean.TRUE ) - .isNicHotUnPlug( Boolean.FALSE ) - .isDiscVirtioHotPlug( Boolean.TRUE ) - .isDiscVirtioHotUnPlug( Boolean.FALSE ) - .build() ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertNotNull( serverId ); - assertEquals( serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop" ); + String serverId = api.createServer(Server.Request.creatingBuilder() + .dataCenterId(dataCenterId) + .name(name) + .cores(4) + .ram(4 * 1024) + .bootFromImageId(imageId) + .hasInternetAccess(Boolean.TRUE) + .lanId(2) + .osType(OsType.LINUX) + .availabilityZone(AvailabilityZone.ZONE_1) + .isCpuHotPlug(Boolean.TRUE) + .isRamHotPlug(Boolean.FALSE) + .isNicHotPlug(Boolean.TRUE) + .isNicHotUnPlug(Boolean.FALSE) + .isDiscVirtioHotPlug(Boolean.TRUE) + .isDiscVirtioHotUnPlug(Boolean.FALSE) + .build()); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(serverId); + assertEquals(serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop"); } finally { pbApi.close(); server.shutdown(); @@ -262,9 +268,9 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testUpdateServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-update.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-update.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -278,7 +284,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { + "8192" + "" + newName + "" + "" + storageId + "" -// + "?" + // + "?" + "OTHER" + "AUTO" + "false" @@ -290,24 +296,24 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { + "" + ""; try { - String requestId = api.updateServer( Server.Request.updatingBuilder() - .id( serverId ) - .name( newName ) - .cores( 8 ) - .ram( 8 * 1024 ) - .bootFromStorageId( storageId ) - .osType( OsType.OTHER ) - .availabilityZone( AvailabilityZone.AUTO ) - .isCpuHotPlug( false ) - .isRamHotPlug( true ) - .isNicHotPlug( false ) - .isNicHotUnPlug( true ) - .isDiscVirtioHotPlug( false ) - .isDiscVirtioHotUnPlug( true ) - .build() ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertNotNull( requestId ); - assertEquals( requestId, "102458" ); + String requestId = api.updateServer(Server.Request.updatingBuilder() + .id(serverId) + .name(newName) + .cores(8) + .ram(8 * 1024) + .bootFromStorageId(storageId) + .osType(OsType.OTHER) + .availabilityZone(AvailabilityZone.AUTO) + .isCpuHotPlug(false) + .isRamHotPlug(true) + .isNicHotPlug(false) + .isNicHotUnPlug(true) + .isDiscVirtioHotPlug(false) + .isDiscVirtioHotUnPlug(true) + .build()); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(requestId); + assertEquals(requestId, "102458"); } finally { pbApi.close(); server.shutdown(); @@ -317,22 +323,41 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { @Test public void testDeleteServer() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-delete.xml" ) ) ); + server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-delete.xml"))); - ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); ServerApi api = pbApi.serverApi(); String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; - + String content = "" + serverId + ""; try { - boolean result = api.deleteServer( serverId ); - assertRequestHasCommonProperties( server.takeRequest(), content ); - assertTrue( result ); + boolean result = api.deleteServer(serverId); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertTrue(result); } finally { pbApi.close(); server.shutdown(); } } + + @Test + public void testDeleteNonExistingServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ServerApi api = pbApi.serverApi(); + + String id = "random-non-existing-id"; + try { + boolean result = api.deleteServer(id); + assertRequestHasCommonProperties(server.takeRequest()); + assertFalse(result); + } finally { + pbApi.close(); + server.shutdown(); + } + } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java new file mode 100644 index 0000000000..62957015ac --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java @@ -0,0 +1,167 @@ +/* + * 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.profitbricks.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.jclouds.profitbricks.BaseProfitBricksLiveTest; +import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware; +import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate; +import org.jclouds.profitbricks.domain.DataCenter; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.rest.InsufficientResourcesException; +import org.jclouds.util.Predicates2; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +@Test(groups = "live", testName = "StorageApiLiveTest", singleThreaded = true) +public class StorageApiLiveTest extends BaseProfitBricksLiveTest { + + private Predicate waitUntilAvailable; + private DataCenter dataCenter; + private Server server; + private String createdStorageId; + + @Override + protected void initialize() { + super.initialize(); + List dataCenters = api.dataCenterApi().getAllDataCenters(); + assertFalse(dataCenters.isEmpty(), "Must atleast have 1 datacenter available for storage testing."); + + dataCenter = Iterables.getFirst(dataCenters, null); + if (dataCenter != null) + dataCenter = api.dataCenterApi().getDataCenter(dataCenter.id()); // fetch individual to load more properties + + this.waitUntilAvailable = Predicates2.retry( + new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.STORAGE, ProvisioningState.AVAILABLE), + 6l * 60l, 2l, TimeUnit.SECONDS); + } + + @Test(expectedExceptions = InsufficientResourcesException.class) + public void testUberStorage() { + api.storageApi().createStorage( + Storage.Request.creatingBuilder() + .dataCenterId(dataCenter) + .name("Uber Storage") + .size(9999999f) + .build()); + } + + @Test + public void testCreateStorage() { + String storageId = api.storageApi().createStorage( + Storage.Request.creatingBuilder() + .dataCenterId(dataCenter) + .name("hdd-1") + .size(2f) + .build()); + + assertNotNull(storageId); + createdStorageId = storageId; + } + + @Test(dependsOnMethods = "testCreateStorage") + public void testGetStorage() { + Storage storage = api.storageApi().getStorage(createdStorageId); + + assertNotNull(storage); + assertEquals(storage.id(), createdStorageId); + } + + @Test(dependsOnMethods = "testCreateStorage") + public void testGetAllStorages() { + List storages = api.storageApi().getAllStorages(); + + assertNotNull(storages); + assertFalse(storages.isEmpty()); + } + + @Test(dependsOnMethods = "testCreateStorage") + public void testWaitUntilAvailable() { + boolean available = waitUntilAvailable.apply(createdStorageId); + + assertTrue(available); + } + + @Test(dependsOnMethods = "testWaitUntilAvailable") + public void testUpdateStorage() { + String requestId = api.storageApi().updateStorage( + Storage.Request.updatingBuilder() + .id(createdStorageId) + .name("hdd-2") + .size(5l) + .build()); + + assertNotNull(requestId); + waitUntilAvailable.apply(createdStorageId); + + Storage storage = api.storageApi().getStorage(createdStorageId); + assertEquals(storage.size(), 5f); + assertEquals(storage.name(), "hdd-2"); + } + + @Test(dependsOnMethods = "testUpdateStorage") + public void testConnectStorage() { + server = Iterables.getFirst(dataCenter.servers(), null); + assertNotNull(server, "No server to attach to."); + + String requestId = api.storageApi().connectStorageToServer( + Storage.Request.connectingBuilder() + .storageId(createdStorageId) + .serverId(server.id()) + .build() + ); + + assertNotNull(requestId); + waitUntilAvailable.apply(createdStorageId); + + Storage storage = api.storageApi().getStorage(createdStorageId); + assertTrue(storage.serverIds().contains(server.id())); + } + + @Test(dependsOnMethods = "testConnectStorage") + public void testDisconnectStorage() { + String requestId = api.storageApi() + .disconnectStorageFromServer(createdStorageId, server.id()); + + assertNotNull(requestId); + waitUntilAvailable.apply(createdStorageId); + + Storage storage = api.storageApi().getStorage(createdStorageId); + assertFalse(storage.serverIds().contains(server.id())); + } + + @AfterClass(alwaysRun = true) + public void testDeleteStorage() { + if (createdStorageId != null) { + boolean result = api.storageApi().deleteStorage(createdStorageId); + + assertTrue(result, "Created test storage was not delete."); + } + } +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java new file mode 100644 index 0000000000..10a4a491b9 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java @@ -0,0 +1,285 @@ +/* + * 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.profitbricks.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.profitbricks.ProfitBricksApi; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; +import org.testng.annotations.Test; + +import com.squareup.okhttp.mockwebserver.MockResponse; +import com.squareup.okhttp.mockwebserver.MockWebServer; + +@Test(groups = "unit", testName = "StorageApiMockTest") +public class StorageApiMockTest extends BaseProfitBricksMockTest { + + @Test + public void testGetAllStorages() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storages.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + try { + List storages = api.getAllStorages(); + assertRequestHasCommonProperties(server.takeRequest(), ""); + assertNotNull(storages); + assertTrue(storages.size() == 2); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetAllStoragesReturning404() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + try { + List storages = api.getAllStorages(); + assertRequestHasCommonProperties(server.takeRequest()); + assertTrue(storages.isEmpty()); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetStorage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; + + String content = "" + id + ""; + try { + Storage storage = api.getStorage(id); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(storage); + assertEquals(storage.id(), id); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetNonExistingStorage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String id = "random-non-existing-id"; + try { + Storage storage = api.getStorage(id); + assertRequestHasCommonProperties(server.takeRequest()); + assertNull(storage); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testConnectStorageToServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-connect.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; + String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; + + String content = "" + + "" + storageId + "" + + "" + serverId + "" + + "VIRTIO" + + "2" + + ""; + try { + String requestId = api.connectStorageToServer( + Storage.Request.connectingBuilder() + .serverId(serverId) + .storageId(storageId) + .busType(Storage.BusType.VIRTIO) + .deviceNumber(2) + .build() + ); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertEquals(requestId, "16463317"); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testDisconnectStorageFromServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-disconnect.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; + String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; + + String content = "" + + "" + storageId + "" + + "" + serverId + "" + + ""; + + try { + String requestId = api.disconnectStorageFromServer(storageId, serverId); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertEquals(requestId, "16463318"); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testCreateStorage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-create.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + String imageId = "f0a59a5c-7940-11e4-8053-52540066fee9"; + + String content = "" + + "" + dataCenterId + "" + + "hdd-1" + "80" + + "" + imageId + "" + + "qqqqqqqqq" + + ""; + try { + String storageId = api.createStorage( + Storage.Request.creatingBuilder() + .dataCenterId(dataCenterId) + .name("hdd-1") + .size(80f) + .mountImageId(imageId) + .imagePassword("qqqqqqqqq") + .build()); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(storageId); + assertEquals(storageId, "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testUpdateStorage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-update.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; + String imageId = "f4742db0-9160-11e4-9d74-52540066fee9"; + + String content = "" + + "" + storageId + "" + + "20hdd-2" + + "" + imageId + "" + + ""; + try { + String requestId = api.updateStorage( + Storage.Request.updatingBuilder() + .id(storageId) + .size(20f) + .name("hdd-2") + .mountImageId(imageId) + .build()); + + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(requestId); + assertEquals(requestId, "1234568"); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testDeleteStorage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-delete.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; + + String content = "" + storageId + ""; + + try { + boolean result = api.deleteStorage(storageId); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertTrue(result); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testDeleteNonExistingStorage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + StorageApi api = pbApi.storageApi(); + + String id = "random-non-existing-id"; + try { + boolean result = api.deleteStorage(id); + assertRequestHasCommonProperties(server.takeRequest()); + assertFalse(result); + } finally { + pbApi.close(); + server.shutdown(); + } + } +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java index 9198840892..8658e2d9ae 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java @@ -20,12 +20,16 @@ import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWeb import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; +import org.jclouds.http.HttpResponseException; import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.DataCenter; import org.jclouds.profitbricks.domain.Location; +import org.jclouds.profitbricks.domain.Server; import org.jclouds.profitbricks.features.DataCenterApi; +import org.jclouds.profitbricks.features.ServerApi; import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.InsufficientResourcesException; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; @@ -38,6 +42,8 @@ import com.squareup.okhttp.mockwebserver.MockWebServer; @Test(groups = "unit", testName = "ResponseStatusFromPayloadHttpCommandExecutorServiceTest") public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends BaseProfitBricksMockTest { + private final int MAX_RETRIES = 5; + @Test public void testNotFound() throws Exception { MockWebServer server = mockWebServer(); @@ -95,4 +101,43 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas server.shutdown(); } } + + @Test + public void testOverLimitSettings() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/fault-413.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl("/")); + ServerApi api = pbApi.serverApi(); + + try { + api.createServer(Server.Request.CreatePayload.create("some-datacenter-id", "node1", 99, 12800)); + fail("Request should have failed."); + } catch (Exception ex) { + assertTrue(ex instanceof InsufficientResourcesException, "Exception should be InsufficientResourcesException"); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testServiceUnderMaintenance() throws Exception { + MockWebServer server = mockWebServer(); + for (int i = 0; i <= MAX_RETRIES; i++) // jclouds retries 5 times + server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/maintenance-503.html"))); + + ProfitBricksApi pbApi = api(server.getUrl("/")); + DataCenterApi api = pbApi.dataCenterApi(); + + try { + api.clearDataCenter("some-datacenter-id"); + fail("Request should have failed."); + } catch (Exception ex) { + assertTrue(ex instanceof HttpResponseException, "Exception should be HttpResponseException"); + } finally { + pbApi.close(); + server.shutdown(); + } + } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java index e6b692be3b..7413d011ea 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java @@ -28,9 +28,9 @@ import org.testng.annotations.Test; public class ProfitBricksSoapMessageEnvelopeTest { private final String SOAP_PREFIX - = "" - + "" - + ""; + = "" + + "" + + ""; private final String SOAP_SUFFIX = ""; private final String endpoint = "https://api.profitbricks.com/1.3"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java index 23bdbc9630..d4817351ad 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java @@ -47,9 +47,9 @@ public abstract class BaseResponseHandlerTest { protected String payloadFromResource(String resource) { try { - return toStringAndClose(getClass().getResourceAsStream(resource)); + return toStringAndClose(getClass().getResourceAsStream(resource)); } catch (IOException e) { - throw Throwables.propagate(e); + throw Throwables.propagate(e); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java index d32b65606a..3ea9ed8807 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java @@ -20,57 +20,57 @@ import org.jclouds.http.functions.ParseSax; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "RequestIdOnlyResponseHandlerTest" ) +@Test(groups = "unit", testName = "RequestIdOnlyResponseHandlerTest") public class RequestIdOnlyResponseHandlerTest extends BaseResponseHandlerTest { @Override protected ParseSax createParser() { - return factory.create( injector.getInstance( RequestIdOnlyResponseHandler.class ) ); + return factory.create(injector.getInstance(RequestIdOnlyResponseHandler.class)); } @Test public void testParseResponseFromStartServer() { ParseSax parser = createParser(); - String requestId = parser.parse( payloadFromResource( "/server/server-start.xml" ) ); + String requestId = parser.parse(payloadFromResource("/server/server-start.xml")); - assertEquals( requestId, "123456" ); + assertEquals(requestId, "123456"); } @Test public void testParseResponseFromStopServer() { ParseSax parser = createParser(); - String requestId = parser.parse( payloadFromResource( "/server/server-stop.xml" ) ); + String requestId = parser.parse(payloadFromResource("/server/server-stop.xml")); - assertEquals( requestId, "123456" ); + assertEquals(requestId, "123456"); } @Test public void testParseResponseFromResetServer() { ParseSax parser = createParser(); - String requestId = parser.parse( payloadFromResource( "/server/server-reset.xml" ) ); + String requestId = parser.parse(payloadFromResource("/server/server-reset.xml")); - assertEquals( requestId, "123456" ); + assertEquals(requestId, "123456"); } @Test public void testParseResponseFromUpdateServer() { ParseSax parser = createParser(); - String requestId = parser.parse( payloadFromResource( "/server/server-update.xml" ) ); + String requestId = parser.parse(payloadFromResource("/server/server-update.xml")); - assertEquals( requestId, "102458" ); + assertEquals(requestId, "102458"); } @Test public void testParseResponseFromDeleteServer() { ParseSax parser = createParser(); - String requestId = parser.parse( payloadFromResource( "/server/server-delete.xml" ) ); + String requestId = parser.parse(payloadFromResource("/server/server-delete.xml")); - assertEquals( requestId, "102459" ); + assertEquals(requestId, "102459"); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java index cb8484167f..2b54dd5820 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java @@ -38,11 +38,11 @@ public class ServiceFaultResponseHandlerTest extends BaseResponseHandlerTest { @@ -35,19 +42,57 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest parser = createParser(); + DataCenter actual = parser.parse(payloadFromResource("/datacenter/datacenter.xml")); assertNotNull(actual, "Parsed content returned null"); + DateCodec dateParser = createDateParser().iso8601(); + DataCenter expected = DataCenter.builder() - .id("12345678-abcd-efgh-ijkl-987654321000") - .version(10) - .name("JClouds-DC") - .state(ProvisioningState.AVAILABLE) - .location(Location.US_LAS) - .build(); - assertEquals(expected, actual); + .id("12345678-abcd-efgh-ijkl-987654321000") + .version(10) + .name("JClouds-DC") + .state(ProvisioningState.AVAILABLE) + .location(Location.US_LAS) + .servers(ImmutableList.of( + Server.builder() + .id("12345678-abcd-efgh-ijkl-987654321000") + .name("jnode1") + .cores(4) + .ram(4096) + .hasInternetAccess(true) + .state(ProvisioningState.AVAILABLE) + .status(Server.Status.RUNNING) + .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z")) + .osType(OsType.LINUX) + .availabilityZone(AvailabilityZone.AUTO) + .isCpuHotPlug(true) + .isRamHotPlug(true) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .build() + )) + .storages(ImmutableList.of( + Storage.builder() + .id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh") + .size(40) + .name("jnode1-disk1") + .state(ProvisioningState.AVAILABLE) + .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z")) + .build() + )) + .build(); + assertEquals(actual, expected); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java index b957b5240d..7e738ae5c5 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java @@ -45,8 +45,8 @@ public class DataCenterListResponseHandlerTest extends BaseResponseHandlerTest expected = ImmutableList.of( - DataCenter.builder().id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").name("JClouds-DC").version(10).state(ProvisioningState.AVAILABLE).build(), - DataCenter.builder().id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy").name("Random DC").version(238).state(ProvisioningState.INPROCESS).build() + DataCenter.builder().id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").name("JClouds-DC").version(10).state(ProvisioningState.AVAILABLE).build(), + DataCenter.builder().id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy").name("Random DC").version(238).state(ProvisioningState.INPROCESS).build() ); assertEquals(expected, actual); } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java index d09f362090..fb2e33d90b 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java @@ -25,41 +25,41 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ImageInfoResponseHandlerTest" ) +@Test(groups = "unit", testName = "ImageInfoResponseHandlerTest") public class ImageInfoResponseHandlerTest extends BaseResponseHandlerTest { @Override protected ParseSax createParser() { - return factory.create( injector.getInstance( ImageInfoResponseHandler.class ) ); + return factory.create(injector.getInstance(ImageInfoResponseHandler.class)); } @Test public void testParseResponseFromGetImage() { ParseSax parser = createParser(); - Image actual = parser.parse( payloadFromResource( "/image/image.xml" ) ); - assertNotNull( actual, "Parsed content returned null" ); + Image actual = parser.parse(payloadFromResource("/image/image.xml")); + assertNotNull(actual, "Parsed content returned null"); Image expected = Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "5ad99c9e-9166-11e4-9d74-52540066fee9" ) - .name( "Ubuntu-14.04-LTS-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.US_LAS ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("5ad99c9e-9166-11e4-9d74-52540066fee9") + .name("Ubuntu-14.04-LTS-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.US_LAS) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(); - assertEquals( expected, actual ); + assertEquals(expected, actual); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java index 0aa8f58fcc..48271389e8 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java @@ -27,157 +27,157 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ImageListResponseHandlerTest" ) +@Test(groups = "unit", testName = "ImageListResponseHandlerTest") public class ImageListResponseHandlerTest extends BaseResponseHandlerTest> { @Override protected ParseSax> createParser() { - return factory.create( injector.getInstance( ImageListResponseHandler.class ) ); + return factory.create(injector.getInstance(ImageListResponseHandler.class)); } @Test public void testParseResponseFromGetAllImages() { ParseSax> parser = createParser(); - List actual = parser.parse( payloadFromResource( "/image/images.xml" ) ); - assertNotNull( actual, "Parsed content returned null" ); + List actual = parser.parse(payloadFromResource("/image/images.xml")); + assertNotNull(actual, "Parsed content returned null"); List expected = ImmutableList.of( Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "e4f73936-9161-11e4-9d74-52540066fee9" ) - .name( "Ubuntu-12.04-LTS-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.DE_FRA ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("e4f73936-9161-11e4-9d74-52540066fee9") + .name("Ubuntu-12.04-LTS-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.DE_FRA) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(), Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "a984a5d3-9163-11e4-9d74-52540066fee9" ) - .name( "Ubuntu-14.04-LTS-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.DE_FRA ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("a984a5d3-9163-11e4-9d74-52540066fee9") + .name("Ubuntu-14.04-LTS-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.DE_FRA) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(), Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "5f3cac96-915f-11e4-9d74-52540066fee9" ) - .name( "Debian-jessie-prerelease-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.UNRECOGNIZED ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("5f3cac96-915f-11e4-9d74-52540066fee9") + .name("Debian-jessie-prerelease-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.UNRECOGNIZED) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(), Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "f4742db0-9160-11e4-9d74-52540066fee9" ) - .name( "Fedora-19-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.UNRECOGNIZED ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("f4742db0-9160-11e4-9d74-52540066fee9") + .name("Fedora-19-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.UNRECOGNIZED) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(), Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "86902c18-9164-11e4-9d74-52540066fee9" ) - .name( "Ubuntu-12.04-LTS-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.UNRECOGNIZED ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("86902c18-9164-11e4-9d74-52540066fee9") + .name("Ubuntu-12.04-LTS-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.UNRECOGNIZED) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(), Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "3b48e3ff-9163-11e4-9d74-52540066fee9" ) - .name( "Ubuntu-14.04-LTS-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.DE_FKB ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("3b48e3ff-9163-11e4-9d74-52540066fee9") + .name("Ubuntu-14.04-LTS-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.DE_FKB) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build(), Image.builder() - .isBootable( true ) - .isCpuHotPlug( true ) - .isCpuHotUnPlug( false ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) - .id( "6ce17716-9164-11e4-9d74-52540066fee9" ) - .name( "Ubuntu-12.04-LTS-server-2015-01-01" ) - .size( 2048f ) - .type( Image.Type.HDD ) - .location( Location.US_LAS ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .osType( OsType.LINUX ) - .isPublic( true ) - .isRamHotPlug( true ) - .isRamHotUnPlug( false ) - .isWriteable( true ) + .isBootable(true) + .isCpuHotPlug(true) + .isCpuHotUnPlug(false) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) + .id("6ce17716-9164-11e4-9d74-52540066fee9") + .name("Ubuntu-12.04-LTS-server-2015-01-01") + .size(2048f) + .type(Image.Type.HDD) + .location(Location.US_LAS) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .osType(OsType.LINUX) + .isPublic(true) + .isRamHotPlug(true) + .isRamHotUnPlug(false) + .isWriteable(true) .build() ); - assertEquals( expected, actual ); + assertEquals(expected, actual); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java index 700b1e5bf5..19bc29d1c8 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java @@ -21,20 +21,20 @@ import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ServerIdOnlyResponseHandlerTest" ) +@Test(groups = "unit", testName = "ServerIdOnlyResponseHandlerTest") public class ServerIdOnlyResponseHandlerTest extends BaseResponseHandlerTest { @Override protected ParseSax createParser() { - return factory.create( injector.getInstance( ServerIdOnlyResponseHandler.class ) ); + return factory.create(injector.getInstance(ServerIdOnlyResponseHandler.class)); } @Test public void testParseResponseFromCreateServer() { ParseSax parser = createParser(); - String serverId = parser.parse( payloadFromResource( "/server/server-create.xml" ) ); + String serverId = parser.parse(payloadFromResource("/server/server-create.xml")); - assertEquals( "qwertyui-qwer-qwer-qwer-qwertyyuiiop", serverId ); + assertEquals("qwertyui-qwer-qwer-qwer-qwertyyuiiop", serverId); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java index 734e169ee5..b05056811d 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java @@ -16,7 +16,9 @@ */ package org.jclouds.profitbricks.http.parser.server; -import java.text.ParseException; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + import org.jclouds.date.DateCodec; import org.jclouds.date.DateCodecFactory; import org.jclouds.http.functions.ParseSax; @@ -25,52 +27,51 @@ import org.jclouds.profitbricks.domain.OsType; import org.jclouds.profitbricks.domain.ProvisioningState; import org.jclouds.profitbricks.domain.Server; import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; + import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ServerInfoResponseHandlerTest" ) +@Test(groups = "unit", testName = "ServerInfoResponseHandlerTest") public class ServerInfoResponseHandlerTest extends BaseResponseHandlerTest { @Override protected ParseSax createParser() { - return factory.create( injector.getInstance( ServerInfoResponseHandler.class ) ); + return factory.create(injector.getInstance(ServerInfoResponseHandler.class)); } protected DateCodecFactory createDateParser() { - return injector.getInstance( DateCodecFactory.class ); + return injector.getInstance(DateCodecFactory.class); } @Test - public void testParseResponseFromGetServer() throws ParseException { + public void testParseResponseFromGetServer() { ParseSax parser = createParser(); - Server actual = parser.parse( payloadFromResource( "/server/server.xml" ) ); - assertNotNull( actual, "Parsed content returned null" ); + Server actual = parser.parse(payloadFromResource("/server/server.xml")); + assertNotNull(actual, "Parsed content returned null"); DateCodec dateParser = createDateParser().iso8601(); Server expected = Server.builder() - .id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" ) - .name( "facebook-node" ) - .cores( 4 ) - .ram( 4096 ) - .hasInternetAccess( true ) - .state( ProvisioningState.AVAILABLE ) - .status( Server.Status.RUNNING ) - .creationTime( dateParser.toDate( "2014-12-04T07:09:23.138Z" ) ) - .lastModificationTime( dateParser.toDate( "2014-12-12T03:08:35.629Z" ) ) - .osType( OsType.LINUX ) - .availabilityZone( AvailabilityZone.AUTO ) - .isCpuHotPlug( true ) - .isRamHotPlug( true ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) + .id("qwertyui-qwer-qwer-qwer-qwertyyuiiop") + .name("facebook-node") + .cores(4) + .ram(4096) + .hasInternetAccess(true) + .state(ProvisioningState.AVAILABLE) + .status(Server.Status.RUNNING) + .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z")) + .osType(OsType.LINUX) + .availabilityZone(AvailabilityZone.AUTO) + .isCpuHotPlug(true) + .isRamHotPlug(true) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) .build(); - assertEquals( actual, expected ); + assertEquals(actual, expected); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java index c9c01c68f5..09ee5bb6b5 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java @@ -30,68 +30,68 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.testng.annotations.Test; -@Test( groups = "unit", testName = "ServerListResponseHandlerTest" ) +@Test(groups = "unit", testName = "ServerListResponseHandlerTest") public class ServerListResponseHandlerTest extends BaseResponseHandlerTest> { @Override protected ParseSax> createParser() { - return factory.create( injector.getInstance( ServerListResponseHandler.class ) ); + return factory.create(injector.getInstance(ServerListResponseHandler.class)); } protected DateCodecFactory createDateParser() { - return injector.getInstance( DateCodecFactory.class ); + return injector.getInstance(DateCodecFactory.class); } @Test public void testParseResponseFromGetAllServers() { ParseSax> parser = createParser(); - List actual = parser.parse( payloadFromResource( "/server/servers.xml" ) ); - assertNotNull( actual, "Parsed content returned null" ); + List actual = parser.parse(payloadFromResource("/server/servers.xml")); + assertNotNull(actual, "Parsed content returned null"); DateCodec dateParser = createDateParser().iso8601(); List expected = ImmutableList.of( Server.builder() - .id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" ) - .name( "facebook-node" ) - .cores( 4 ) - .ram( 4096 ) - .hasInternetAccess( true ) - .state( ProvisioningState.AVAILABLE ) - .status( Server.Status.RUNNING ) - .creationTime( dateParser.toDate( "2014-12-04T07:09:23.138Z" ) ) - .lastModificationTime( dateParser.toDate( "2014-12-12T03:08:35.629Z" ) ) - .osType( OsType.LINUX ) - .availabilityZone( AvailabilityZone.AUTO ) - .isCpuHotPlug( true ) - .isRamHotPlug( true ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) + .id("qwertyui-qwer-qwer-qwer-qwertyyuiiop") + .name("facebook-node") + .cores(4) + .ram(4096) + .hasInternetAccess(true) + .state(ProvisioningState.AVAILABLE) + .status(Server.Status.RUNNING) + .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z")) + .osType(OsType.LINUX) + .availabilityZone(AvailabilityZone.AUTO) + .isCpuHotPlug(true) + .isRamHotPlug(true) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) .build(), Server.builder() - .id( "asdfghjk-asdf-asdf-asdf-asdfghjklkjl" ) - .name( "google-node" ) - .cores( 1 ) - .ram( 1024 ) - .hasInternetAccess( false ) - .state( ProvisioningState.AVAILABLE ) - .status( Server.Status.RUNNING ) - .creationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) ) - .lastModificationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) ) - .osType( OsType.LINUX ) - .availabilityZone( AvailabilityZone.AUTO ) - .isCpuHotPlug( true ) - .isRamHotPlug( true ) - .isNicHotPlug( true ) - .isNicHotUnPlug( true ) - .isDiscVirtioHotPlug( true ) - .isDiscVirtioHotUnPlug( true ) + .id("asdfghjk-asdf-asdf-asdf-asdfghjklkjl") + .name("google-node") + .cores(1) + .ram(1024) + .hasInternetAccess(false) + .state(ProvisioningState.AVAILABLE) + .status(Server.Status.RUNNING) + .creationTime(dateParser.toDate("2014-11-12T07:01:00.441Z")) + .lastModificationTime(dateParser.toDate("2014-11-12T07:01:00.441Z")) + .osType(OsType.LINUX) + .availabilityZone(AvailabilityZone.AUTO) + .isCpuHotPlug(true) + .isRamHotPlug(true) + .isNicHotPlug(true) + .isNicHotUnPlug(true) + .isDiscVirtioHotPlug(true) + .isDiscVirtioHotUnPlug(true) .build() ); - assertEquals( actual, expected ); + assertEquals(actual, expected); } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java index 0f9822bdba..3bd2755236 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java @@ -40,70 +40,70 @@ public class GetProvisioningStateResponseHandlerTest extends BaseResponseHandler ParseSax parser = createParser(); for (Map.Entry pair : sampleResponses.entrySet()) { - ProvisioningState actual = parser.parse(pair.getValue()); - assertNotNull(actual, "Parsed content returned null"); + ProvisioningState actual = parser.parse(pair.getValue()); + assertNotNull(actual, "Parsed content returned null"); - assertEquals(pair.getKey(), actual); + assertEquals(pair.getKey(), actual); } } private final Map sampleResponses = new LinkedHashMap() { { - put(ProvisioningState.INACTIVE, - "\n" - + " \n" - + " \n" - + " \n" - + " INACTIVE\n" - + " \n" - + " \n" - + ""); - put(ProvisioningState.INPROCESS, - "\n" - + " \n" - + " \n" - + " \n" - + " INPROCESS\n" - + " \n" - + " \n" - + ""); - put(ProvisioningState.AVAILABLE, - "\n" - + " \n" - + " \n" - + " \n" - + " AVAILABLE\n" - + " \n" - + " \n" - + ""); - put(ProvisioningState.DELETED, - "\n" - + " \n" - + " \n" - + " \n" - + " DELETED\n" - + " \n" - + " \n" - + ""); - put(ProvisioningState.ERROR, - "\n" - + " \n" - + " \n" - + " \n" - + " ERROR\n" - + " \n" - + " \n" - + ""); - put(ProvisioningState.UNRECOGNIZED, - "\n" - + " \n" - + " \n" - + " \n" - + " MEH\n" - + " \n" - + " \n" - + ""); + put(ProvisioningState.INACTIVE, + "\n" + + " \n" + + " \n" + + " \n" + + " INACTIVE\n" + + " \n" + + " \n" + + ""); + put(ProvisioningState.INPROCESS, + "\n" + + " \n" + + " \n" + + " \n" + + " INPROCESS\n" + + " \n" + + " \n" + + ""); + put(ProvisioningState.AVAILABLE, + "\n" + + " \n" + + " \n" + + " \n" + + " AVAILABLE\n" + + " \n" + + " \n" + + ""); + put(ProvisioningState.DELETED, + "\n" + + " \n" + + " \n" + + " \n" + + " DELETED\n" + + " \n" + + " \n" + + ""); + put(ProvisioningState.ERROR, + "\n" + + " \n" + + " \n" + + " \n" + + " ERROR\n" + + " \n" + + " \n" + + ""); + put(ProvisioningState.UNRECOGNIZED, + "\n" + + " \n" + + " \n" + + " \n" + + " MEH\n" + + " \n" + + " \n" + + ""); } }; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandlerTest.java new file mode 100644 index 0000000000..def23b66f8 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageIdOnlyResponseHandlerTest.java @@ -0,0 +1,42 @@ +/* + * 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.profitbricks.http.parser.storage; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "StorageIdOnlyResponseHandlerTest") +public class StorageIdOnlyResponseHandlerTest extends BaseResponseHandlerTest { + + @Override + protected ParseSax createParser() { + return factory.create(injector.getInstance(StorageIdOnlyResponseHandler.class)); + } + + @Test + public void testParseResponseFromCreateStorage() { + ParseSax parser = createParser(); + + String storageId = parser.parse(payloadFromResource("/storage/storage-create.xml")); + + assertEquals("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh", storageId); + } + +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandlerTest.java new file mode 100644 index 0000000000..338b02b79f --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageInfoResponseHandlerTest.java @@ -0,0 +1,66 @@ +/* + * 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.profitbricks.http.parser.storage; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.date.DateCodec; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +@Test(groups = "unit", testName = "StorageInfoResponseHandlerTest") +public class StorageInfoResponseHandlerTest extends BaseResponseHandlerTest { + + @Override + protected ParseSax createParser() { + return factory.create(injector.getInstance(StorageInfoResponseHandler.class)); + } + + protected DateCodecFactory createDateParser() { + return injector.getInstance(DateCodecFactory.class); + } + + @Test + public void testParseResponseFromGetStorage() { + ParseSax parser = createParser(); + + Storage actual = parser.parse(payloadFromResource("/storage/storage.xml")); + assertNotNull(actual, "Parsed content returned null"); + + DateCodec dateParser = createDateParser().iso8601(); + + Storage expected = Storage.builder() + .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") + .size(40) + .name("hdd-1") + .state(ProvisioningState.AVAILABLE) + .serverIds(ImmutableList.of("qwertyui-qwer-qwer-qwer-qwertyyuiiop")) + .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z")) + .build(); + + assertEquals(actual, expected); + } + +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandlerTest.java new file mode 100644 index 0000000000..62e43fca85 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/storage/StorageListResponseHandlerTest.java @@ -0,0 +1,80 @@ +/* + * 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.profitbricks.http.parser.storage; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +import org.jclouds.date.DateCodec; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Storage; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; + +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "StorageListResponseHandlerTest") +public class StorageListResponseHandlerTest extends BaseResponseHandlerTest> { + + @Override + protected ParseSax> createParser() { + return factory.create(injector.getInstance(StorageListResponseHandler.class)); + } + + protected DateCodecFactory createDateParser() { + return injector.getInstance(DateCodecFactory.class); + } + + @Test + public void testParseResponseFromGetAllStorages() { + ParseSax> parser = createParser(); + + List actual = parser.parse(payloadFromResource("/storage/storages.xml")); + assertNotNull(actual, "Parsed content returned null"); + + DateCodec dateParser = createDateParser().iso8601(); + + List expected = ImmutableList.of( + Storage.builder() + .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") + .size(40f) + .name("hdd-1") + .state(ProvisioningState.AVAILABLE) + .serverIds(ImmutableList.of("qwertyui-qwer-qwer-qwer-qwertyyuiiop")) + .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z")) + .build(), + Storage.builder() + .id("asfasfle-f23n-cu89-klfr-njkdsvwllkfa") + .size(100f) + .name("hdd-2") + .state(ProvisioningState.INPROCESS) + .serverIds(ImmutableList.of("asdfghjk-asdf-asdf-asdf-asdfghjklkjl")) + .creationTime(dateParser.toDate("2014-11-04T07:09:23.138Z")) + .lastModificationTime(dateParser.toDate("2014-11-12T03:14:48.316Z")) + .build() + ); + + assertEquals(actual, expected); + } + +} diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java index 3e5d19a697..d5883a61f6 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java @@ -46,11 +46,11 @@ public class BaseProfitBricksMockTest { protected static final String authHeader = BasicAuthentication.basic("username", "password"); protected static final String provider = "profitbricks"; protected static final String rootUrl = "/1.3"; - + private static final String SOAP_PREFIX - = "" - + "" - + ""; + = "" + + "" + + ""; private static final String SOAP_SUFFIX = ""; @@ -77,7 +77,7 @@ public class BaseProfitBricksMockTest { server.play(); return server; } - + public byte[] payloadFromResource(String resource) { try { return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); @@ -85,9 +85,9 @@ public class BaseProfitBricksMockTest { throw Throwables.propagate(e); } } - - protected static String payloadSoapWithBody(String body){ - return SOAP_PREFIX.concat( body ).concat( SOAP_SUFFIX ); + + protected static String payloadSoapWithBody(String body) { + return SOAP_PREFIX.concat(body).concat(SOAP_SUFFIX); } protected static void assertRequestHasCommonProperties(final RecordedRequest request) { @@ -96,9 +96,9 @@ public class BaseProfitBricksMockTest { assertEquals(request.getHeader(HttpHeaders.AUTHORIZATION), authHeader); assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.TEXT_XML); } - - protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content ){ - assertEquals( new String( request.getBody() ), payloadSoapWithBody( content ) ); - assertRequestHasCommonProperties( request ); + + protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content) { + assertEquals(new String(request.getBody()), payloadSoapWithBody(content)); + assertRequestHasCommonProperties(request); } } diff --git a/providers/profitbricks/src/test/resources/datacenter/datacenter.xml b/providers/profitbricks/src/test/resources/datacenter/datacenter.xml index 2911c81bce..9d8e20ab75 100644 --- a/providers/profitbricks/src/test/resources/datacenter/datacenter.xml +++ b/providers/profitbricks/src/test/resources/datacenter/datacenter.xml @@ -33,7 +33,7 @@ 12345678-abcd-efgh-ijkl-987654321000 202.94.38.12 02:01:09:cd:f0:b0 - ` + false llllllll-kkkk-jjjj-hhhh-gggggggggggg 62383ec1-38c8-486b-8fa2-a3bb0a5edd97 diff --git a/providers/profitbricks/src/test/resources/fault-404.xml b/providers/profitbricks/src/test/resources/fault-404.xml index 430be821d2..18751027aa 100644 --- a/providers/profitbricks/src/test/resources/fault-404.xml +++ b/providers/profitbricks/src/test/resources/fault-404.xml @@ -14,4 +14,4 @@ - + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/fault-413.xml b/providers/profitbricks/src/test/resources/fault-413.xml new file mode 100644 index 0000000000..b4d5f795d5 --- /dev/null +++ b/providers/profitbricks/src/test/resources/fault-413.xml @@ -0,0 +1,17 @@ + + + + + S:Server + New request exceeds the current capacity settings of this user contract. Please refer to Request Id : 16503940. [VDC-5-1020] Server has 12,800 MiB configured RAM. Your personal limit is 10,240 MiB per server. + + + OVER_LIMIT_SETTING + 413 + New request exceeds the current capacity settings of this user contract. Please refer to Request Id : 16503940. [VDC-5-1020] Server has 12,800 MiB configured RAM. Your personal limit is 10,240 MiB per server. + 16503940 + + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/maintenance-503.html b/providers/profitbricks/src/test/resources/maintenance-503.html new file mode 100644 index 0000000000..bbc1b1fa5b --- /dev/null +++ b/providers/profitbricks/src/test/resources/maintenance-503.html @@ -0,0 +1,67 @@ + + + + + Profitbricks | Maintenance + + + + + + + +

+
+
+ +
+
+ + + +
+ +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/server/server-state-inprocess.xml b/providers/profitbricks/src/test/resources/server/server-state-inprocess.xml new file mode 100644 index 0000000000..122191a99f --- /dev/null +++ b/providers/profitbricks/src/test/resources/server/server-state-inprocess.xml @@ -0,0 +1,28 @@ + + + + + + 16577212 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 22 + qwertyui-qwer-qwer-qwer-qwertyyuiiop + 1 + 512 + false + INPROCESS + NOSTATE + 2015-01-29T00:37:49.096Z + 2015-01-29T00:37:49.096Z + UNKNOWN + AUTO + false + false + false + false + false + false + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage-connect.xml b/providers/profitbricks/src/test/resources/storage/storage-connect.xml new file mode 100644 index 0000000000..79673e2c3b --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage-connect.xml @@ -0,0 +1,13 @@ + + + + + + + 16463317 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 49 + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage-create.xml b/providers/profitbricks/src/test/resources/storage/storage-create.xml new file mode 100644 index 0000000000..3e1d1f3aa7 --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage-create.xml @@ -0,0 +1,14 @@ + + + + + + + 1234567 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 45 + qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage-delete.xml b/providers/profitbricks/src/test/resources/storage/storage-delete.xml new file mode 100644 index 0000000000..a9731261d3 --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage-delete.xml @@ -0,0 +1,13 @@ + + + + + + + 12345679 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 47 + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage-disconnect.xml b/providers/profitbricks/src/test/resources/storage/storage-disconnect.xml new file mode 100644 index 0000000000..8726fe2bd3 --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage-disconnect.xml @@ -0,0 +1,13 @@ + + + + + + + 16463318 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 50 + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage-state-inprocess.xml b/providers/profitbricks/src/test/resources/storage/storage-state-inprocess.xml new file mode 100644 index 0000000000..85c47173df --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage-state-inprocess.xml @@ -0,0 +1,23 @@ + + + + + + 16463316 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 49 + qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh + 40 + hdd-1 + + f0a59a5c-7940-11e4-8053-52540066fee9 + Ubuntu-14.04-LTS-server-2014-12-01 + + qwertyui-qwer-qwer-qwer-qwertyyuiiop + INPROCESS + 2014-12-04T07:09:23.138Z + 2014-12-12T03:14:48.316Z + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage-update.xml b/providers/profitbricks/src/test/resources/storage/storage-update.xml new file mode 100644 index 0000000000..ff71f32a02 --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage-update.xml @@ -0,0 +1,13 @@ + + + + + + + 1234568 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 46 + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storage.xml b/providers/profitbricks/src/test/resources/storage/storage.xml new file mode 100644 index 0000000000..fe4dfc535a --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storage.xml @@ -0,0 +1,23 @@ + + + + + + 16463316 + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 49 + qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh + 40 + hdd-1 + + f0a59a5c-7940-11e4-8053-52540066fee9 + Ubuntu-14.04-LTS-server-2014-12-01 + + qwertyui-qwer-qwer-qwer-qwertyyuiiop + AVAILABLE + 2014-12-04T07:09:23.138Z + 2014-12-12T03:14:48.316Z + + + + \ No newline at end of file diff --git a/providers/profitbricks/src/test/resources/storage/storages.xml b/providers/profitbricks/src/test/resources/storage/storages.xml new file mode 100644 index 0000000000..a7328617db --- /dev/null +++ b/providers/profitbricks/src/test/resources/storage/storages.xml @@ -0,0 +1,37 @@ + + + + + + aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + 49 + qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh + 40 + hdd-1 + + f0a59a5c-7940-11e4-8053-52540066fee9 + Ubuntu-14.04-LTS-server-2014-12-01 + + qwertyui-qwer-qwer-qwer-qwertyyuiiop + AVAILABLE + 2014-12-04T07:09:23.138Z + 2014-12-12T03:14:48.316Z + + + qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy + 238 + asfasfle-f23n-cu89-klfr-njkdsvwllkfa + 100 + hdd-2 + + f4742db0-9160-11e4-9d74-52540066fee9 + Fedora-19-server-2015-01-01 + + asdfghjk-asdf-asdf-asdf-asdfghjklkjl + INPROCESS + 2014-11-04T07:09:23.138Z + 2014-11-12T03:14:48.316Z + + + + \ No newline at end of file