JCLOUDS-702: JCloud ProfitBricks provider - Server & Image API
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/ee24ddb2 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/ee24ddb2 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/ee24ddb2 Branch: refs/heads/master Commit: ee24ddb2b4d9001f8fdf47a483985c0c2c912bb4 Parents: 8206d19 Author: Reijhanniel <[email protected]> Authored: Fri Jan 23 10:05:41 2015 +0800 Committer: Ignasi Barrera <[email protected]> Committed: Mon Jan 26 11:27:18 2015 +0100 ---------------------------------------------------------------------- providers/profitbricks/pom.xml | 8 +- .../jclouds/profitbricks/ProfitBricksApi.java | 8 + .../binder/BaseProfitBricksRequestBinder.java | 2 +- .../server/CreateServerRequestBinder.java | 57 +++ .../server/UpdateServerRequestBinder.java | 56 +++ .../internal/ProvisioningStatusAware.java | 2 +- .../ProvisioningStatusPollingPredicate.java | 2 + .../profitbricks/domain/AvailabilityZone.java | 35 ++ .../org/jclouds/profitbricks/domain/Image.java | 207 +++++++++ .../org/jclouds/profitbricks/domain/OsType.java | 30 ++ .../org/jclouds/profitbricks/domain/Server.java | 424 +++++++++++++++++++ .../domain/internal/ServerCommonProperties.java | 49 +++ .../jclouds/profitbricks/features/ImageApi.java | 65 +++ .../profitbricks/features/ServerApi.java | 164 +++++++ .../parser/BaseProfitBricksResponseHandler.java | 8 + .../parser/RequestIdOnlyResponseHandler.java | 49 +++ .../parser/image/BaseImageResponseHandler.java | 76 ++++ .../parser/image/ImageInfoResponseHandler.java | 48 +++ .../parser/image/ImageListResponseHandler.java | 51 +++ .../server/BaseServerResponseHandler.java | 75 ++++ .../server/ServerIdOnlyResponseHandler.java | 55 +++ .../server/ServerInfoResponseHandler.java | 48 +++ .../server/ServerListResponseHandler.java | 51 +++ .../server/CreateServerRequestBinderTest.java | 65 +++ .../server/UpdateServerRequestBinderTest.java | 64 +++ .../profitbricks/domain/ServerBuilderTest.java | 164 +++++++ .../features/DataCenterApiMockTest.java | 41 +- .../profitbricks/features/ImageApiLiveTest.java | 58 +++ .../profitbricks/features/ImageApiMockTest.java | 116 +++++ .../features/ServerApiLiveTest.java | 139 ++++++ .../features/ServerApiMockTest.java | 338 +++++++++++++++ .../RequestIdOnlyResponseHandlerTest.java | 76 ++++ .../parser/ServiceFaultResponseHandlerTest.java | 4 +- .../DataCenterInfoResponseHandlerTest.java | 3 +- .../image/ImageInfoResponseHandlerTest.java | 65 +++ .../image/ImageListResponseHandlerTest.java | 183 ++++++++ .../server/ServerIdOnlyResponseHandlerTest.java | 40 ++ .../server/ServerInfoResponseHandlerTest.java | 76 ++++ .../server/ServerListResponseHandlerTest.java | 97 +++++ .../internal/BaseProfitBricksMockTest.java | 18 +- .../datacenter/datacenter-not-found.xml | 17 + .../src/test/resources/fault-404.xml | 30 +- .../test/resources/image/image-not-found.xml | 17 + .../src/test/resources/image/image.xml | 26 ++ .../src/test/resources/image/images.xml | 140 ++++++ .../src/test/resources/server/server-create.xml | 13 + .../src/test/resources/server/server-delete.xml | 13 + .../src/test/resources/server/server-reset.xml | 11 + .../src/test/resources/server/server-start.xml | 11 + .../src/test/resources/server/server-stop.xml | 11 + .../src/test/resources/server/server-update.xml | 13 + .../src/test/resources/server/server.xml | 57 +++ .../src/test/resources/server/servers.xml | 104 +++++ 53 files changed, 3542 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/pom.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/pom.xml b/providers/profitbricks/pom.xml index b48e589..84f49b4 100644 --- a/providers/profitbricks/pom.xml +++ b/providers/profitbricks/pom.xml @@ -57,13 +57,13 @@ <version>${jclouds.version}</version> </dependency> <dependency> - <groupId>com.google.auto.value</groupId> - <artifactId>auto-value</artifactId> + <groupId>com.google.auto.service</groupId> + <artifactId>auto-service</artifactId> <scope>provided</scope> </dependency> <dependency> - <groupId>com.google.auto.service</groupId> - <artifactId>auto-service</artifactId> + <groupId>com.google.auto.value</groupId> + <artifactId>auto-value</artifactId> <scope>provided</scope> </dependency> <!-- Test dependencies --> http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java ---------------------------------------------------------------------- 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 d1cb1e1..7ab121a 100644 --- a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java @@ -19,10 +19,18 @@ package org.jclouds.profitbricks; 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.rest.annotations.Delegate; public interface ProfitBricksApi extends Closeable { @Delegate DataCenterApi dataCenterApi(); + + @Delegate + ImageApi imageApi(); + + @Delegate + ServerApi serverApi(); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/BaseProfitBricksRequestBinder.java ---------------------------------------------------------------------- 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 af85c5e..8c2d36b 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 @@ -56,7 +56,7 @@ public abstract class BaseProfitBricksRequestBinder<T> implements MapBinder { protected abstract String createPayload(T payload); protected String formatIfNotEmpty(String pattern, Object param) { - return Strings.isNullOrEmpty(param.toString()) ? "" : String.format(pattern, param); + return Strings.isNullOrEmpty(nullableToString( param )) ? "" : String.format(pattern, param); } protected String nullableToString(Object object) { http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinder.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..4acf33b --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinder.java @@ -0,0 +1,57 @@ +/* + * 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.server; + +import static java.lang.String.format; +import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder; +import org.jclouds.profitbricks.domain.Server; + +public class CreateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.CreatePayload> { + + protected final StringBuilder requestBuilder; + + CreateServerRequestBinder() { + super( "server" ); + this.requestBuilder = new StringBuilder( 128 * 4 ); + } + + @Override + protected String createPayload( Server.Request.CreatePayload payload ) { + requestBuilder.append( "<ws:createServer>" ) + .append( "<request>" ) + .append( format( "<dataCenterId>%s</dataCenterId>", payload.dataCenterId() ) ) + .append( format( "<cores>%s</cores>", payload.cores() ) ) + .append( format( "<ram>%s</ram>", payload.ram() ) ) + .append( formatIfNotEmpty( "<serverName>%s</serverName>", payload.name() ) ) + .append( formatIfNotEmpty( "<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId() ) ) + .append( formatIfNotEmpty( "<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId() ) ) + .append( formatIfNotEmpty( "<internetAccess>%s</internetAccess>", payload.hasInternetAccess() ) ) + .append( formatIfNotEmpty( "<lanId>%s</lanId>", payload.lanId() ) ) + .append( formatIfNotEmpty( "<osType>%s</osType>", payload.osType() ) ) + .append( formatIfNotEmpty( "<availabilityZone>%s</availabilityZone>", payload.availabilityZone() ) ) + .append( formatIfNotEmpty( "<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug() ) ) + .append( formatIfNotEmpty( "<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug() ) ) + .append( formatIfNotEmpty( "<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug() ) ) + .append( formatIfNotEmpty( "<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug() ) ) + .append( formatIfNotEmpty( "<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug() ) ) + .append( formatIfNotEmpty( "<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug() ) ) + .append( "</request>" ) + .append( "</ws:createServer>" ); + return requestBuilder.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinder.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..d051b88 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinder.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.server; + +import static java.lang.String.format; +import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder; +import org.jclouds.profitbricks.domain.Server; + +public class UpdateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.UpdatePayload> { + + protected final StringBuilder requestBuilder; + + UpdateServerRequestBinder() { + super( "server" ); + this.requestBuilder = new StringBuilder( 128 * 4 ); + + } + + @Override + protected String createPayload( Server.Request.UpdatePayload payload ) { + requestBuilder.append( "<ws:updateServer>" ) + .append( "<request>" ) + .append( format( "<serverId>%s</serverId>", payload.id() ) ) + .append( format( "<cores>%s</cores>", payload.cores() ) ) + .append( format( "<ram>%s</ram>", payload.ram() ) ) + .append( formatIfNotEmpty( "<serverName>%s</serverName>", payload.name() ) ) + .append( formatIfNotEmpty( "<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId() ) ) + .append( formatIfNotEmpty( "<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId() ) ) + .append( formatIfNotEmpty( "<osType>%s</osType>", payload.osType() ) ) + .append( formatIfNotEmpty( "<availabilityZone>%s</availabilityZone>", payload.availabilityZone() ) ) + .append( formatIfNotEmpty( "<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug() ) ) + .append( formatIfNotEmpty( "<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug() ) ) + .append( formatIfNotEmpty( "<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug() ) ) + .append( formatIfNotEmpty( "<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug() ) ) + .append( formatIfNotEmpty( "<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug() ) ) + .append( formatIfNotEmpty( "<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug() ) ) + .append( "</request>" ) + .append( "</ws:updateServer>" ); + return requestBuilder.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java ---------------------------------------------------------------------- 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 84f7128..5056243 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; + DATACENTER, SERVER; } http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java ---------------------------------------------------------------------- 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 d8a7521..73db33f 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 @@ -48,6 +48,8 @@ public class ProvisioningStatusPollingPredicate implements Predicate<String> { switch (domain) { case DATACENTER: return expect == api.dataCenterApi().getDataCenterState(input); + case SERVER: + return expect == api.serverApi().getServer( input ).state(); default: throw new IllegalArgumentException("Unknown domain '" + domain + "'"); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/AvailabilityZone.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..b582d69 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/AvailabilityZone.java @@ -0,0 +1,35 @@ +/* + * 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; + +public enum AvailabilityZone { + + AUTO, ZONE_1, ZONE_2, UNRECOGNIZED; + + public String value() { + return name(); + } + + public static AvailabilityZone fromValue( String v ) { + try { + return valueOf( v ); + } catch ( Exception ex ) { + return UNRECOGNIZED; + } + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Image.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Image.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Image.java new file mode 100644 index 0000000..d272e27 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Image.java @@ -0,0 +1,207 @@ +/* + * 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; + +@AutoValue +public abstract class Image { + + public enum Type { + + HDD, CDROM, UNRECOGNIZED; + + public static Type fromValue(String v) { + try { + return valueOf(v); + } catch (IllegalArgumentException ex) { + return UNRECOGNIZED; + } + } + } + + public abstract String id(); + + public abstract String name(); + + public abstract float size(); // MB + + public abstract Type type(); + + public abstract Location location(); + + public abstract OsType osType(); + + public abstract boolean isPublic(); + + public abstract boolean isWriteable(); + + public abstract boolean isBootable(); + + public abstract boolean isCpuHotPlug(); + + public abstract boolean isCpuHotUnPlug(); + + public abstract boolean isRamHotPlug(); + + public abstract boolean isRamHotUnPlug(); + + public abstract boolean isNicHotPlug(); + + public abstract boolean isNicHotUnPlug(); + + public abstract boolean isDiscVirtioHotPlug(); + + public abstract boolean isDiscVirtioHotUnPlug(); + + public static Image create(String id, String name, float size, Type type, Location location, OsType osType, + boolean isPublic, boolean isWriteable, boolean isBootable, boolean cpuHotPlug, boolean cpuHotUnPlug, + boolean ramHotPlug, boolean ramHotUnPlug, boolean nicHotPlug, boolean nicHotUnPlug, + boolean discVirtioHotPlug, boolean discVirtioHotUnPlug) { + return new AutoValue_Image(id, name, size, type, location, osType, isPublic, isWriteable, + isBootable, cpuHotPlug, cpuHotUnPlug, ramHotPlug, ramHotUnPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromImage(this); + } + + public static class Builder { + + private String id; + private String name; + private float size; + private Type type; + private Location location; + private OsType osType; + private boolean isPublic; + private boolean isWriteable; + private boolean isBootable; + private boolean cpuHotPlug; + private boolean cpuHotUnPlug; + private boolean ramHotPlug; + private boolean ramHotUnPlug; + private boolean nicHotPlug; + private boolean nicHotUnPlug; + private boolean discVirtioHotPlug; + private boolean discVirtioHotUnPlug; + + 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 type(Type type) { + this.type = type; + return this; + } + + public Builder osType(OsType osType) { + this.osType = osType; + return this; + } + + public Builder location(Location location) { + this.location = location; + return this; + } + + public Builder isPublic(boolean isPublic) { + this.isPublic = isPublic; + return this; + } + + public Builder isWriteable(boolean isWriteable) { + this.isWriteable = isWriteable; + return this; + } + + public Builder isBootable(boolean isBootable) { + this.isBootable = isBootable; + return this; + } + + public Builder isCpuHotPlug(boolean cpuHotPlug) { + this.cpuHotPlug = cpuHotPlug; + return this; + } + + public Builder isCpuHotUnPlug(boolean cpuHotUnPlug) { + this.cpuHotUnPlug = cpuHotUnPlug; + return this; + } + + public Builder isRamHotPlug(boolean ramHotPlug) { + this.ramHotPlug = ramHotPlug; + return this; + } + + public Builder isRamHotUnPlug(boolean ramHotUnPlug) { + this.ramHotUnPlug = ramHotUnPlug; + return this; + } + + public Builder isNicHotPlug(boolean nicHotPlug) { + this.nicHotPlug = nicHotPlug; + return this; + } + + public Builder isNicHotUnPlug(boolean nicHotUnPlug) { + this.nicHotUnPlug = nicHotUnPlug; + return this; + } + + public Builder isDiscVirtioHotPlug(boolean discVirtioHotPlug) { + this.discVirtioHotPlug = discVirtioHotPlug; + return this; + } + + public Builder isDiscVirtioHotUnPlug(boolean discVirtioHotUnPlug) { + this.discVirtioHotUnPlug = discVirtioHotUnPlug; + return this; + } + + public Image build() { + return Image.create(id, name, size, type, location, osType, isPublic, isWriteable, isBootable, cpuHotPlug, cpuHotUnPlug, + ramHotPlug, ramHotUnPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug); + } + + public Builder fromImage(Image in) { + return this.id(in.id()).isBootable(in.isBootable()).isCpuHotPlug(in.isCpuHotPlug()).isCpuHotUnPlug(in.isCpuHotUnPlug()) + .isDiscVirtioHotPlug(in.isDiscVirtioHotPlug()).isDiscVirtioHotUnPlug(in.isDiscVirtioHotUnPlug()) + .isNicHotPlug(in.isNicHotPlug()).isNicHotUnPlug(in.isNicHotUnPlug()).isPublic(in.isPublic()) + .isRamHotPlug(in.isRamHotPlug()).isRamHotUnPlug(in.isRamHotUnPlug()).isWriteable(in.isWriteable()) + .location(in.location()).name(in.name()).osType(in.osType()).size(in.size()); + } + + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/OsType.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/OsType.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/OsType.java new file mode 100644 index 0000000..c21f1c4 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/OsType.java @@ -0,0 +1,30 @@ +/* + * 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; + +public enum OsType { + + WINDOWS, LINUX, OTHER, UNRECOGNIZED; + + public static OsType fromValue(String v) { + try { + return valueOf(v); + } catch (IllegalArgumentException ex) { + return UNRECOGNIZED; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Server.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..703eb59 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Server.java @@ -0,0 +1,424 @@ +/* + * 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 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 org.jclouds.javax.annotation.Nullable; + +@AutoValue +public abstract class Server implements ServerCommonProperties { + + public enum Status { + + NOSTATE, RUNNING, BLOCKED, PAUSED, SHUTDOWN, SHUTOFF, CRASHED, UNRECOGNIZED; + + public String value() { + return name(); + } + + public static Status fromValue( String v ) { + try { + return valueOf( v ); + } catch ( IllegalArgumentException ex ) { + return UNRECOGNIZED; + } + } + } + + @Nullable + public abstract String id(); + + @Nullable + @Override + public abstract String name(); + + @Nullable + public abstract Boolean hasInternetAccess(); + + public abstract ProvisioningState state(); + + @Nullable + public abstract Status status(); + + @Nullable + public abstract OsType osType(); + + @Nullable + public abstract AvailabilityZone availabilityZone(); + + @Nullable + public abstract Date creationTime(); + + @Nullable + public abstract Date lastModificationTime(); + +// public abstract List<Storage> storages(); +// public abstract List<Nic> 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 ); + + } + + public static DescribingBuilder builder() { + return new DescribingBuilder(); + } + + public DescribingBuilder toBuilder() { + return builder().fromServer( this ); + } + + public abstract static class Builder<B extends Builder, D extends ServerCommonProperties> { + + protected String name; + protected int cores; + protected int ram; + protected Boolean cpuHotPlug; + protected Boolean ramHotPlug; + protected Boolean nicHotPlug; + protected Boolean nicHotUnPlug; + protected Boolean discVirtioHotPlug; + protected Boolean discVirtioHotUnPlug; + + public B name( String name ) { + this.name = name; + return self(); + } + + public B cores( int cores ) { + this.cores = cores; + return self(); + } + + public B ram( int ram ) { + this.ram = ram; + return self(); + } + + public B isCpuHotPlug( Boolean cpuHotPlug ) { + this.cpuHotPlug = cpuHotPlug; + return self(); + } + + public B isRamHotPlug( Boolean ramHotPlug ) { + this.ramHotPlug = ramHotPlug; + return self(); + + } + + public B isNicHotPlug( Boolean nicHotPlug ) { + this.nicHotPlug = nicHotPlug; + return self(); + } + + public B isNicHotUnPlug( Boolean nicHotUnPlug ) { + this.nicHotUnPlug = nicHotUnPlug; + return self(); + } + + public B isDiscVirtioHotPlug( Boolean discVirtioHotPlug ) { + this.discVirtioHotPlug = discVirtioHotPlug; + return self(); + } + + public B isDiscVirtioHotUnPlug( Boolean discVirtioHotUnPlug ) { + this.discVirtioHotUnPlug = discVirtioHotUnPlug; + return self(); + } + + public abstract B self(); + + public abstract D build(); + } + + public static class DescribingBuilder extends Builder<DescribingBuilder, Server> { + + private String id; + private ProvisioningState state; + private Status status; + private OsType osType; + private AvailabilityZone zone; + private Date creationTime; + private Date lastModificationTime; + private Boolean hasInternetAccess; + + public DescribingBuilder id( String id ) { + this.id = id; + return this; + } + + public DescribingBuilder state( ProvisioningState state ) { + this.state = state; + return this; + } + + public DescribingBuilder status( Status status ) { + this.status = status; + return this; + } + + public DescribingBuilder osType( OsType osType ) { + this.osType = osType; + return this; + } + + public DescribingBuilder availabilityZone( AvailabilityZone zone ) { + this.zone = zone; + return this; + } + + public DescribingBuilder creationTime( Date creationTime ) { + this.creationTime = creationTime; + return this; + } + + public DescribingBuilder lastModificationTime( Date lastModificationTime ) { + this.lastModificationTime = lastModificationTime; + return this; + } + + public DescribingBuilder hasInternetAccess( Boolean hasInternetAccess ) { + this.hasInternetAccess = hasInternetAccess; + 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 ); + } + + 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() ); + } + + @Override + public DescribingBuilder self() { + return this; + } + + } + + public static final class Request { + + public static CreatePayload.Builder creatingBuilder() { + return new CreatePayload.Builder(); + } + + public static UpdatePayload.Builder updatingBuilder() { + return new UpdatePayload.Builder(); + } + + @AutoValue + public abstract static class CreatePayload implements ServerCommonProperties { + + public abstract String dataCenterId(); + + @Nullable + public abstract String bootFromStorageId(); + + @Nullable + public abstract String bootFromImageId(); + + @Nullable + public abstract Integer lanId(); + + @Nullable + public abstract Boolean hasInternetAccess(); + + @Nullable + public abstract AvailabilityZone availabilityZone(); + + @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 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, + isDiscVirtioHotUnPlug, name, cores, ram, dataCenterId, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess, + availabilityZone, osType ); + } + + public static class Builder extends Server.Builder<Builder, CreatePayload> { + + private String dataCenterId; + private String bootFromStorageId; + private String bootFromImageId; + private Integer lanId; + private Boolean hasInternetAccess; + private AvailabilityZone availabilityZone; + private OsType osType; + + 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 bootFromStorageId( String storageId ) { + this.bootFromStorageId = storageId; + return this; + } + + public Builder bootFromImageId( String image ) { + this.bootFromImageId = image; + return this; + } + + public Builder lanId( Integer lanId ) { + this.lanId = lanId; + return this; + } + + public Builder availabilityZone( AvailabilityZone zone ) { + this.availabilityZone = zone; + return this; + } + + public Builder osType( OsType osType ) { + this.osType = osType; + return this; + } + + public Builder hasInternetAccess( Boolean hasInternetAccess ) { + this.hasInternetAccess = hasInternetAccess; + return this; + } + + @Override + public Builder self() { + return this; + } + + @Override + public CreatePayload build() { + return CreatePayload.create( dataCenterId, name, cores, ram, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess, + availabilityZone, osType, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug ); + } + + } + } + + @AutoValue + public abstract static class UpdatePayload implements ServerCommonProperties { + + @Nullable + @Override + public abstract String name(); + + public abstract String id(); + + @Nullable + public abstract String bootFromStorageId(); + + @Nullable + public abstract String bootFromImageId(); + + @Nullable + public abstract AvailabilityZone availabilityZone(); + + @Nullable + public abstract OsType osType(); + + 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 ); + } + + public static class Builder extends Server.Builder<Builder, UpdatePayload> { + + private String id; + private String bootFromStorageId; + private String bootFromImageId; + private AvailabilityZone availabilityZone; + private OsType osType; + + public Builder id( String id ) { + this.id = id; + return this; + } + + public Builder bootFromStorageId( String storageId ) { + this.bootFromStorageId = storageId; + return this; + } + + public Builder bootFromImageId( String image ) { + this.bootFromImageId = image; + return this; + } + + public Builder availabilityZone( AvailabilityZone zone ) { + this.availabilityZone = zone; + return this; + } + + public Builder osType( OsType osType ) { + this.osType = osType; + return this; + } + + @Override + public Builder self() { + return this; + } + + @Override + public UpdatePayload build() { + return UpdatePayload.create( id, name, cores, ram, bootFromStorageId, bootFromImageId, availabilityZone, osType, + cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug ); + + } + + } + } + + } + + 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)" ); + + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/internal/ServerCommonProperties.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/internal/ServerCommonProperties.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/internal/ServerCommonProperties.java new file mode 100644 index 0000000..7366fb1 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/domain/internal/ServerCommonProperties.java @@ -0,0 +1,49 @@ +/* + * 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.internal; + +import org.jclouds.javax.annotation.Nullable; + +/** + * An interface used as common data type for {@link org.jclouds.profitbricks.domain.Server.Builder} + */ +public interface ServerCommonProperties { + + @Nullable + Boolean isCpuHotPlug(); + + @Nullable + Boolean isRamHotPlug(); + + @Nullable + Boolean isNicHotPlug(); + + @Nullable + Boolean isNicHotUnPlug(); + + @Nullable + Boolean isDiscVirtioHotPlug(); + + @Nullable + Boolean isDiscVirtioHotUnPlug(); + + String name(); + + int cores(); + + int ram(); // in MB +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ImageApi.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ImageApi.java b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ImageApi.java new file mode 100644 index 0000000..95d27c4 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ImageApi.java @@ -0,0 +1,65 @@ +/* + * 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.domain.Image; +import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope; +import org.jclouds.profitbricks.http.parser.image.ImageInfoResponseHandler; +import org.jclouds.profitbricks.http.parser.image.ImageListResponseHandler; +import org.jclouds.rest.annotations.Fallback; +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 ImageApi { + + /** + * @return Outputs a list of all HDD and/or CD-ROM/DVD images existing on or uploaded to the ProfitBricks FTP server. + */ + @POST + @Named("image:getall") + @Payload("<ws:getAllImages/>") + @XMLResponseParser(ImageListResponseHandler.class) + @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class) + List<Image> getAllImages(); + + /** + * + * @param identifier Image Id + * @return Returns information about a HDD or CD-ROM/DVD (ISO) image. + */ + @POST + @Named("image:get") + @Payload("<ws:getImage><imageId>{id}</imageId></ws:getImage>") + @XMLResponseParser(ImageInfoResponseHandler.class) + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + Image getImage(@PayloadParam("id") String identifier); +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ServerApi.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..1fa89b3 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/features/ServerApi.java @@ -0,0 +1,164 @@ +/* + * 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.server.CreateServerRequestBinder; +import org.jclouds.profitbricks.binder.server.UpdateServerRequestBinder; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope; +import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler; +import org.jclouds.profitbricks.http.parser.server.ServerIdOnlyResponseHandler; +import org.jclouds.profitbricks.http.parser.server.ServerInfoResponseHandler; +import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler; +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 ServerApi { + + /** + * @return Returns information about all virtual server, such as configuration, provisioning status, power status, etc. + */ + @POST + @Named( "server:getall" ) + @Payload( "<ws:getAllServers/>" ) + @XMLResponseParser( ServerListResponseHandler.class ) + @Fallback( Fallbacks.EmptyListOnNotFoundOr404.class ) + List<Server> getAllServers(); + + /** + * @param identifier Identifier of the virtual server + * @return Returns information about a virtual server, such as configuration, provisioning status, power status, etc. + */ + @POST + @Named( "server:get" ) + @Payload( "<ws:getServer><serverId>{id}</serverId></ws:getServer>" ) + @XMLResponseParser( ServerInfoResponseHandler.class ) + @Fallback( Fallbacks.NullOnNotFoundOr404.class ) + Server getServer( @PayloadParam( "id" ) String identifier ); + + /** + * Starts an existing virtual server + * <ul> + * <li>Server may receive new public IP addresses if necessary </li> + * <li>Billing will continue</li> + * </ul> + * + * + * @param id Identifier of the target virtual server + * @return Identifier of current request + */ + @POST + @Named( "server:start" ) + @Payload( "<ws:startServer><serverId>{id}</serverId></ws:startServer>" ) + @XMLResponseParser( RequestIdOnlyResponseHandler.class ) + String startServer( @PayloadParam( "id" ) String id ); + + /** + * + * Stops an existing virtual server forcefully (HARD stop) + * <ul> + * <li>Server will be forcefully powered off. Any unsaved data may be lost! </li> + * <li>Billing for this server will be stopped </li> + * <li>When restarting the server a new public IP gets assigned, alternatively, you can reserve IP addresses, see reservation of public + * IP blocks</li> + * </ul> + * + * A graceful stop of a server is not possible through the ProfitBricks API. We recommend to access and execute the command on the + * virtual server directly. Once the server was shutdown you still can use the "stopServer" method that will stop billing. + * + * @param id Identifier of the target virtual server + * @return Identifier of current request + */ + @POST + @Named( "server:stop" ) + @Payload( "<ws:stopServer><serverId>{id}</serverId></ws:stopServer>" ) + @XMLResponseParser( RequestIdOnlyResponseHandler.class ) + String stopServer( @PayloadParam( "id" ) String id ); + + /** + * Resets an existing virtual server (POWER CYCLE). + * <ul> + * <li>Server will be forcefully powered off and restarted immediately. Any unsaved data may be lost!</li> + * <li> Billing will continue</li> + * </ul> + * <b>Graceful REBOOT</b> + * + * A graceful reboot of a server is not possible through the ProfitBricks API. We recommend to access and execute the command on the + * virtual server directly. + * + * @param id Identifier of the target virtual server + * @return Identifier of current request + */ + @POST + @Named( "server:reset" ) + @Payload( "<ws:resetServer><serverId>{id}</serverId></ws:resetServer>" ) + @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 + * an existing LAN or the Internet. + * + * @param payload Payload + * @return serverId of the created server + */ + @POST + @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 + * @return Identifier of current request + */ + @POST + @Named( "server:update" ) + @MapBinder( UpdateServerRequestBinder.class ) + @XMLResponseParser( RequestIdOnlyResponseHandler.class ) + String updateServer( @PayloadParam( "server" ) Server.Request.UpdatePayload payload ); + + /** + * Deletes an existing Virtual Server. + * + * @param id Identifier of the target virtual server + * @return Identifier of current request + */ + @POST + @Named( "server:delete" ) + @Payload( "<ws:deleteServer><serverId>{id}</serverId></ws:deleteServer>" ) + @Fallback( Fallbacks.FalseOnNotFoundOr404.class ) + boolean deleteServer( @PayloadParam( "id" ) String id ); + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/BaseProfitBricksResponseHandler.java ---------------------------------------------------------------------- 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 9e66159..c61f2b5 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 @@ -49,6 +49,14 @@ public abstract class BaseProfitBricksResponseHandler<T> extends ParseSax.Handle return strBuilder.toString().trim(); } + protected Float textToFloatValue() { + return Float.valueOf(textToStringValue()); + } + + protected Double textToDoubleValue(){ + return Double.valueOf( textToStringValue()); + } + protected int textToIntValue() { return Integer.parseInt(textToStringValue()); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..6e6b288 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandler.java @@ -0,0 +1,49 @@ +/* + * 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; + +import com.google.inject.Inject; +import org.jclouds.date.DateCodecFactory; +import org.xml.sax.SAXException; + +public class RequestIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> { + + private String requestId; + + @Inject + RequestIdOnlyResponseHandler( DateCodecFactory dateCodec ) { + super( dateCodec ); + } + + @Override + public void endElement( String uri, String localName, String qName ) throws SAXException { + setPropertyOnEndTag( qName ); + clearTextBuffer(); + } + + @Override + protected void setPropertyOnEndTag( String qName ) { + if ( "requestId".equals( qName ) ) + requestId = textToStringValue(); + } + + @Override + public String getResult() { + return requestId; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/BaseImageResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..1a6ff94 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/BaseImageResponseHandler.java @@ -0,0 +1,76 @@ +/* + * 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.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; +import org.jclouds.profitbricks.domain.OsType; +import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; + +public abstract class BaseImageResponseHandler<T> extends BaseProfitBricksResponseHandler<T> { + + protected Image.Builder builder; + + @Inject + BaseImageResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + this.builder = Image.builder(); + } + + @Override + protected void setPropertyOnEndTag(String qName) { + if ("imageId".equals(qName)) + builder.id(textToStringValue()); + else if ("imageName".equals(qName)) + builder.name(textToStringValue()); + else if ("imageSize".equals(qName)) + builder.size(textToFloatValue()); + else if ("imageType".equals(qName)) + builder.type(Type.fromValue(textToStringValue())); + else if ("location".equals(qName)) + builder.location(Location.fromId(textToStringValue())); + else if ("osType".equals(qName)) + builder.osType(OsType.fromValue(textToStringValue())); + else if ("public".equals(qName)) + builder.isPublic(textToBooleanValue()); + else if ("writeable".equals(qName)) + builder.isWriteable(textToBooleanValue()); + else if ("bootable".equals(qName)) + builder.isBootable(textToBooleanValue()); + else if ("cpuHotPlug".equals(qName)) + builder.isCpuHotPlug(textToBooleanValue()); + else if ("cpuHotUnPlug".equals(qName)) + builder.isCpuHotUnPlug(textToBooleanValue()); + else if ("ramHotPlug".equals(qName)) + builder.isRamHotPlug(textToBooleanValue()); + else if ("ramHotUnPlug".equals(qName)) + builder.isRamHotUnPlug(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()); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..0736acb --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandler.java @@ -0,0 +1,48 @@ +/* + * 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.image; + +import com.google.inject.Inject; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Image; +import org.xml.sax.SAXException; + +public class ImageInfoResponseHandler extends BaseImageResponseHandler<Image> { + + private boolean done = false; + + @Inject + ImageInfoResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (done) + return; + setPropertyOnEndTag(qName); + if ("return".equals(qName)) + done = true; + clearTextBuffer(); + } + + @Override + public Image getResult() { + return builder.build(); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..8fc8091 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandler.java @@ -0,0 +1,51 @@ +/* + * 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.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; + +public class ImageListResponseHandler extends BaseImageResponseHandler<List<Image>> { + + private final List<Image> images; + + @Inject + ImageListResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + this.images = Lists.newArrayList(); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + setPropertyOnEndTag(qName); + if ("return".equals(qName)) { + images.add(builder.build()); + builder = Image.builder(); + } + clearTextBuffer(); + } + + @Override + public List<Image> getResult() { + return images; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..e594ce4 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/BaseServerResponseHandler.java @@ -0,0 +1,75 @@ +/* + * 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.server; + +import com.google.inject.Inject; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.AvailabilityZone; +import org.jclouds.profitbricks.domain.OsType; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler; + +public abstract class BaseServerResponseHandler<T> extends BaseProfitBricksResponseHandler<T> { + + protected Server.DescribingBuilder builder; + + @Inject + BaseServerResponseHandler( DateCodecFactory dateCodec ) { + super( dateCodec ); + this.builder = Server.builder(); + } + + @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() ); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..ed88018 --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandler.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.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; + +/** + * Handler for parsing SOAP response where <i>serverId</i> is the only <i>usable</i> value. + * + * Other properties available (which are ignored): requestId, dataCenterId, dataCenterVersion + */ +public class ServerIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> { + + private String serverId; + + @Inject + ServerIdOnlyResponseHandler( DateCodecFactory dateCodec ) { + super( dateCodec ); + } + + @Override + public void endElement( String uri, String localName, String qName ) throws SAXException { + setPropertyOnEndTag( qName ); + clearTextBuffer(); + } + + @Override + protected void setPropertyOnEndTag( String qName ) { + if ( "serverId".equals( qName ) ) + serverId = textToStringValue(); + } + + @Override + public String getResult() { + return serverId; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..dfac4ff --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandler.java @@ -0,0 +1,48 @@ +/* + * 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.server; + +import com.google.inject.Inject; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Server; +import org.xml.sax.SAXException; + +public class ServerInfoResponseHandler extends BaseServerResponseHandler<Server> { + + private boolean done = false; + + @Inject + ServerInfoResponseHandler( 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; + clearTextBuffer(); + } + + @Override + public Server getResult() { + return builder.build(); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..f50027c --- /dev/null +++ b/providers/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandler.java @@ -0,0 +1,51 @@ +/* + * 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.server; + +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.Server; +import org.xml.sax.SAXException; + +public class ServerListResponseHandler extends BaseServerResponseHandler<List<Server>> { + + private final List<Server> servers; + + @Inject + 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() ); + builder = Server.builder(); + } + clearTextBuffer(); + } + + @Override + public List<Server> getResult() { + return servers; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinderTest.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..bf18841 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/CreateServerRequestBinderTest.java @@ -0,0 +1,65 @@ +/* + * 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.server; + +import org.jclouds.profitbricks.domain.Server; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "CreateServerRequestBinderTest" ) +public class CreateServerRequestBinderTest { + + @Test + public void testCreatePayload() { + 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" ) + .build(); + + String actual = binder.createPayload( payload ); + assertNotNull( actual, "Binder returned null payload" ); + assertEquals( actual, expectedPayload ); + } + + private final String expectedPayload + = ( " <ws:createServer>\n" + + " <request>\n" + + " <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n" + + " <cores>4</cores>\n" + + " <ram>4096</ram>\n" + + " <serverName>jclouds-node</serverName>\n" +// + " <bootFromStorageId>?</bootFromStorageId>\n" +// + " <bootFromImageId>?</bootFromImageId>\n" +// + " <internetAccess>false</internetAccess>\n" +// + " <lanId>?</lanId>\n" +// + " <osType>?</osType>\n" +// + " <availabilityZone>AUTO</availabilityZone>\n" +// + " <cpuHotPlug>false</cpuHotPlug>\n" +// + " <ramHotPlug>false</ramHotPlug>\n" +// + " <nicHotPlug>false</nicHotPlug>\n" +// + " <nicHotUnPlug>false</nicHotUnPlug>\n" +// + " <discVirtioHotPlug>false</discVirtioHotPlug>\n" +// + " <discVirtioHotUnPlug>false</discVirtioHotUnPlug>\n" + + " </request>\n" + + " </ws:createServer>" ) + .replaceAll( "\\s+", "" ); +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinderTest.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..cba666b --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/server/UpdateServerRequestBinderTest.java @@ -0,0 +1,64 @@ +/* + * 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.server; + +import org.jclouds.profitbricks.domain.Server; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "UpdateServerRequestBinderTest" ) +public class UpdateServerRequestBinderTest { + + @Test + public void testCreatePayload() { + 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") + .build(); + + String actual = binder.createPayload( payload ); + assertNotNull(actual, "Binder returned null payload"); + assertEquals(actual, expectedPayload); + } + + private final String expectedPayload + = ( " <ws:updateServer>\n" + + " <request>\n" + + " <serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>\n" + + " <cores>8</cores>\n" + + " <ram>8192</ram>\n" + + " <serverName>apache-node</serverName>\n" +// + " <bootFromStorageId>?</bootFromStorageId>\n" +// + " <bootFromImageId>?</bootFromImageId>\n" +// + " <osType>?</osType>\n" +// + " <availabilityZone>?</availabilityZone>\n" +// + " <cpuHotPlug>?</cpuHotPlug>\n" +// + " <ramHotPlug>?</ramHotPlug>\n" +// + " <nicHotPlug>?</nicHotPlug>\n" +// + " <nicHotUnPlug>?</nicHotUnPlug>\n" +// + " <discVirtioHotPlug>?</discVirtioHotPlug>\n" +// + " <discVirtioHotUnPlug>?</discVirtioHotUnPlug>\n" + + " </request>\n" + + " </ws:updateServer>" ) + .replaceAll( "\\s+", "" ); + +}
