You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/03/08 21:24:15 UTC
[1/3] jclouds-labs git commit: Profitbricks Snapshot api
Repository: jclouds-labs
Updated Branches:
refs/heads/master e97ddaeeb -> e6305c26e
Profitbricks Snapshot api
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/47a5f5d0
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/47a5f5d0
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/47a5f5d0
Branch: refs/heads/master
Commit: 47a5f5d0c53d17cd9d613b34ed9524747a788746
Parents: e97ddae
Author: jasminSPC <ja...@stackpointcloud.com>
Authored: Mon Mar 2 18:03:54 2015 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Sun Mar 8 21:10:20 2015 +0100
----------------------------------------------------------------------
.../jclouds/profitbricks/ProfitBricksApi.java | 5 +-
.../snapshot/CreateSnapshotRequestBinder.java | 44 ++
.../snapshot/RollbackSnapshotRequestBinder.java | 43 ++
.../snapshot/UpdateSnapshotRequestBinder.java | 53 +++
.../internal/ProvisioningStatusAware.java | 2 +-
.../ProvisioningStatusPollingPredicate.java | 2 +
.../jclouds/profitbricks/domain/Snapshot.java | 432 +++++++++++++++++++
.../profitbricks/features/SnapshotApi.java | 87 ++++
.../snapshot/BaseSnapshotResponseHandler.java | 83 ++++
.../snapshot/SnapshotListResponseHandler.java | 52 +++
.../snapshot/SnapshotResponseHandler.java | 48 +++
.../CreateSnapshotRequestBinderTest.java | 47 ++
.../RollbackSnapshotRequestBinderTest.java | 47 ++
.../UpdateSnapshotRequestBinderTest.java | 60 +++
.../ProvisioningStatusPollingPredicateTest.java | 33 ++
.../features/SnapshotApiLiveTest.java | 132 ++++++
.../features/SnapshotApiMockTest.java | 262 +++++++++++
.../SnapshotListResponseHandlerTest.java | 100 +++++
.../snapshot/SnapshotResponseHandlerTest.java | 76 ++++
.../test/resources/snapshot/snapshot-create.xml | 11 +
.../test/resources/snapshot/snapshot-delete.xml | 10 +
.../resources/snapshot/snapshot-rollback.xml | 12 +
.../snapshot/snapshot-state-inprocess.xml | 27 ++
.../test/resources/snapshot/snapshot-update.xml | 10 +
.../src/test/resources/snapshot/snapshot.xml | 27 ++
.../src/test/resources/snapshot/snapshots.xml | 47 ++
26 files changed, 1750 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java b/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
index 49d7e8c..af7a31d 100644
--- a/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
@@ -17,12 +17,12 @@
package org.jclouds.profitbricks;
import java.io.Closeable;
-
import org.jclouds.profitbricks.features.DataCenterApi;
import org.jclouds.profitbricks.features.FirewallApi;
import org.jclouds.profitbricks.features.ImageApi;
import org.jclouds.profitbricks.features.NicApi;
import org.jclouds.profitbricks.features.ServerApi;
+import org.jclouds.profitbricks.features.SnapshotApi;
import org.jclouds.profitbricks.features.StorageApi;
import org.jclouds.rest.annotations.Delegate;
@@ -45,4 +45,7 @@ public interface ProfitBricksApi extends Closeable {
@Delegate
FirewallApi firewallApi();
+
+ @Delegate
+ SnapshotApi snapshotApi();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinder.java b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinder.java
new file mode 100644
index 0000000..213a3a8
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinder.java
@@ -0,0 +1,44 @@
+/*
+ * 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.snapshot;
+
+import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
+import org.jclouds.profitbricks.domain.Snapshot;
+
+import static java.lang.String.format;
+
+public class CreateSnapshotRequestBinder extends BaseProfitBricksRequestBinder<Snapshot.Request.CreatePayload> {
+
+ protected final StringBuilder requestBuilder;
+
+ protected CreateSnapshotRequestBinder() {
+ super("snapshot");
+ this.requestBuilder = new StringBuilder(128);
+ }
+
+ @Override
+ protected String createPayload(Snapshot.Request.CreatePayload payload) {
+ requestBuilder.append("<ws:createSnapshot>")
+ .append("<request>")
+ .append(format("<storageId>%s</storageId>", payload.storageId()))
+ .append(formatIfNotEmpty("<description>%s</description>", payload.description()))
+ .append(formatIfNotEmpty("<snapshotName>%s</snapshotName>", payload.name()))
+ .append("</request>")
+ .append("</ws:createSnapshot>");
+ return requestBuilder.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinder.java b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinder.java
new file mode 100644
index 0000000..a9997cb
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinder.java
@@ -0,0 +1,43 @@
+/*
+ * 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.snapshot;
+
+import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
+import org.jclouds.profitbricks.domain.Snapshot;
+
+import static java.lang.String.format;
+
+public class RollbackSnapshotRequestBinder extends BaseProfitBricksRequestBinder<Snapshot.Request.RollbackPayload> {
+
+ protected final StringBuilder requestBuilder;
+
+ protected RollbackSnapshotRequestBinder() {
+ super("snapshot");
+ this.requestBuilder = new StringBuilder(128);
+ }
+
+ @Override
+ protected String createPayload(Snapshot.Request.RollbackPayload payload) {
+ requestBuilder.append("<ws:rollbackSnapshot>")
+ .append("<request>")
+ .append(format("<snapshotId>%s</snapshotId>", payload.snapshotId()))
+ .append(format("<storageId>%s</storageId>", payload.storageId()))
+ .append("</request>")
+ .append("</ws:rollbackSnapshot>");
+ return requestBuilder.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinder.java b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinder.java
new file mode 100644
index 0000000..e396715
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinder.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.snapshot;
+
+import static java.lang.String.format;
+import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
+import org.jclouds.profitbricks.domain.Snapshot;
+
+public class UpdateSnapshotRequestBinder extends BaseProfitBricksRequestBinder<Snapshot.Request.UpdatePayload> {
+
+ protected final StringBuilder requestBuilder;
+
+ protected UpdateSnapshotRequestBinder() {
+ super("snapshot");
+ this.requestBuilder = new StringBuilder(128);
+ }
+
+ @Override
+ protected String createPayload(Snapshot.Request.UpdatePayload payload) {
+ requestBuilder.append("<ws:updateSnapshot>")
+ .append("<request>")
+ .append(format("<snapshotId>%s</snapshotId>", payload.snapshotId()))
+ .append(format("<description>%s</description>", payload.description()))
+ .append(format("<snapshotName>%s</snapshotName>", payload.name()))
+ .append(formatIfNotEmpty("<bootable>%s</bootable>", payload.bootable()))
+ .append(formatIfNotEmpty("<osType>%s</osType>", payload.osType()))
+ .append(formatIfNotEmpty("<cpuHotPlug>%s</cpuHotPlug>", payload.cpuHotplug()))
+ .append(formatIfNotEmpty("<cpuHotUnPlug>%s</cpuHotUnPlug>", payload.cpuHotunplug()))
+ .append(formatIfNotEmpty("<ramHotPlug>%s</ramHotPlug>", payload.ramHotplug()))
+ .append(formatIfNotEmpty("<ramHotUnPlug>%s</ramHotUnPlug>", payload.ramHotunplug()))
+ .append(formatIfNotEmpty("<nicHotPlug>%s</nicHotPlug>", payload.nicHotplug()))
+ .append(formatIfNotEmpty("<nicHotUnPlug>%s</nicHotUnPlug>", payload.nicHotunplug()))
+ .append(formatIfNotEmpty("<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.discVirtioHotplug()))
+ .append(formatIfNotEmpty("<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.discVirtioHotunplug()))
+ .append("</request>")
+ .append("</ws:updateSnapshot>");
+ return requestBuilder.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java b/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java
index 7a11009..bd00a3d 100644
--- a/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusAware.java
+++ b/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, STORAGE, NIC;
+ DATACENTER, SERVER, STORAGE, NIC, SNAPSHOT;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java b/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java
index 7606cac..f38abad 100644
--- a/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicate.java
@@ -54,6 +54,8 @@ public class ProvisioningStatusPollingPredicate implements Predicate<String> {
return expect == api.storageApi().getStorage(input).state();
case NIC:
return expect == api.nicApi().getNic(input).state();
+ case SNAPSHOT:
+ return expect == api.snapshotApi().getSnapshot(input).state();
default:
throw new IllegalArgumentException("Unknown domain '" + domain + "'");
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Snapshot.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Snapshot.java b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Snapshot.java
new file mode 100644
index 0000000..3182711
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Snapshot.java
@@ -0,0 +1,432 @@
+/*
+ * 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 org.jclouds.javax.annotation.Nullable;
+
+import java.util.Date;
+
+@AutoValue
+public abstract class Snapshot {
+
+ @Nullable
+ public abstract String id();
+
+ @Nullable
+ public abstract String name();
+
+ public abstract float size();
+
+ public abstract boolean bootable();
+
+ @Nullable
+ public abstract String description();
+
+ @Nullable
+ public abstract OsType osType();
+
+ public abstract boolean cpuHotPlug();
+
+ public abstract boolean cpuHotUnPlug();
+
+ public abstract boolean discVirtioHotPlug();
+
+ public abstract boolean discVirtioHotUnPlug();
+
+ public abstract boolean ramHotPlug();
+
+ public abstract boolean ramHotUnPlug();
+
+ public abstract boolean nicHotPlug();
+
+ public abstract boolean nicHotUnPlug();
+
+ @Nullable
+ public abstract Date creationTime();
+
+ @Nullable
+ public abstract Date lastModificationTime();
+
+ @Nullable
+ public abstract ProvisioningState state();
+
+ @Nullable
+ public abstract Location location();
+
+ public static Snapshot create(String id, String name, float size, boolean bootable, String description, OsType osType, boolean cpuHotPlug, boolean cpuHotUnPlug,
+ boolean discVirtioHotPlug, boolean discVirtioHotUnPlug, boolean ramHotPlug, boolean ramHotUnPlug,
+ boolean nicHotPlug, boolean nicHotUnPlug, Date creationTime, Date lastModificationTime, ProvisioningState state, Location location) {
+ return new AutoValue_Snapshot(id, name, size, bootable, description, osType, cpuHotPlug, cpuHotUnPlug,
+ discVirtioHotPlug, discVirtioHotUnPlug, ramHotPlug, ramHotUnPlug,
+ nicHotPlug, nicHotUnPlug, creationTime, lastModificationTime, state, location);
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private String id;
+ @Nullable
+ private String name;
+ private float size;
+ private Date creationTime;
+ private Date lastModificationTime;
+ private ProvisioningState state;
+ private boolean bootable;
+ @Nullable
+ private String description;
+ private OsType osType;
+ private boolean cpuHotPlug;
+ private boolean cpuHotUnPlug;
+ private boolean discVirtioHotPlug;
+ private boolean discVirtioHotUnPlug;
+ private boolean ramHotPlug;
+ private boolean ramHotUnPlug;
+ private boolean nicHotPlug;
+ private boolean nicHotUnPlug;
+ private Location location;
+
+ 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 description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public Builder bootable(Boolean bootable) {
+ this.bootable = bootable;
+ return this;
+ }
+
+ public Builder osType(OsType osType) {
+ this.osType = osType;
+ return this;
+ }
+
+ public Builder cpuHotPlug(boolean cpuHotPlug) {
+ this.cpuHotPlug = cpuHotPlug;
+ return this;
+ }
+
+ public Builder cpuHotUnPlug(boolean cpuHotUnPlug) {
+ this.cpuHotUnPlug = cpuHotUnPlug;
+ return this;
+ }
+
+ public Builder discVirtioHotPlug(boolean discVirtioHotPlug) {
+ this.discVirtioHotPlug = discVirtioHotPlug;
+ return this;
+ }
+
+ public Builder discVirtioHotUnPlug(boolean discVirtioHotUnPlug) {
+ this.discVirtioHotUnPlug = discVirtioHotUnPlug;
+ return this;
+ }
+
+ public Builder ramHotPlug(boolean ramHotPlug) {
+ this.ramHotPlug = ramHotPlug;
+ return this;
+ }
+
+ public Builder ramHotUnPlug(boolean ramHotUnPlug) {
+ this.ramHotUnPlug = ramHotUnPlug;
+ return this;
+ }
+
+ public Builder nicHotPlug(boolean nicHotPlug) {
+ this.nicHotPlug = nicHotPlug;
+ return this;
+ }
+
+ public Builder nicHotUnPlug(boolean nicHotUnPlug) {
+ this.nicHotUnPlug = nicHotUnPlug;
+ return this;
+ }
+
+ public Builder location(Location location) {
+ this.location = location;
+ return this;
+ }
+
+ private Builder fromSnapshot(Snapshot in) {
+ return this.id(in.id()).name(in.name()).size(in.size()).creationTime(in.creationTime())
+ .lastModificationTime(in.lastModificationTime()).state(in.state()).bootable(in.bootable()).description(in.description())
+ .cpuHotPlug(in.cpuHotPlug()).cpuHotUnPlug(in.cpuHotUnPlug()).discVirtioHotPlug(in.discVirtioHotPlug())
+ .discVirtioHotUnPlug(in.discVirtioHotUnPlug()).ramHotPlug(in.ramHotPlug()).ramHotUnPlug(in.ramHotUnPlug())
+ .nicHotPlug(in.nicHotPlug()).nicHotUnPlug(in.nicHotUnPlug());
+ }
+
+ public Snapshot build() {
+ return Snapshot.create(id, name, size, bootable, description, osType, cpuHotPlug, cpuHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug, ramHotPlug, ramHotUnPlug, nicHotPlug, nicHotUnPlug, creationTime, lastModificationTime, state, location);
+ }
+ }
+
+ 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 RollbackPayload.Builder rollbackBuilder() {
+ return new RollbackPayload.Builder();
+ }
+
+ @AutoValue
+ public abstract static class CreatePayload {
+
+ public abstract String storageId();
+
+ public abstract String description();
+
+ public abstract String name();
+
+ public static CreatePayload create(String storageId, String description, String name) {
+ return new AutoValue_Snapshot_Request_CreatePayload(storageId, description, name);
+ }
+
+ public static class Builder {
+
+ private String storageId;
+ private String description;
+ private String name;
+
+ public Builder storageId(String storageId) {
+ this.storageId = storageId;
+ return this;
+ }
+
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public CreatePayload build() {
+ return CreatePayload.create(storageId, description, name);
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class UpdatePayload {
+
+ public abstract String snapshotId();
+
+ public abstract String description();
+
+ public abstract String name();
+
+ public abstract boolean bootable();
+
+ @Nullable
+ public abstract OsType osType();
+
+ public abstract boolean cpuHotplug();
+
+ public abstract boolean cpuHotunplug();
+
+ public abstract boolean ramHotplug();
+
+ public abstract boolean ramHotunplug();
+
+ public abstract boolean nicHotplug();
+
+ public abstract boolean nicHotunplug();
+
+ public abstract boolean discVirtioHotplug();
+
+ public abstract boolean discVirtioHotunplug();
+
+ public static UpdatePayload create(String snapshotId, String description, String name, boolean bootable, OsType osType, boolean cpuHotplug, boolean cpuHotunplug, boolean ramHotplug, boolean ramHotunplug, boolean nicHotplug, boolean nicHotunplug, boolean discVirtioHotplug, boolean discVirtioHotunplug) {
+ return new AutoValue_Snapshot_Request_UpdatePayload(snapshotId, description, name, bootable, osType, cpuHotplug, cpuHotunplug, ramHotplug, ramHotunplug, nicHotplug, nicHotunplug, discVirtioHotplug, discVirtioHotunplug);
+ }
+
+ public static class Builder {
+
+ private String snapshotId;
+
+ @Nullable
+ private String description;
+
+ @Nullable
+ private String name;
+
+ private boolean bootable;
+
+ private OsType osType;
+
+ 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 snapshotId(String snapshotId) {
+ this.snapshotId = snapshotId;
+ return this;
+ }
+
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder bootable(boolean bootable) {
+ this.bootable = bootable;
+ return this;
+ }
+
+ public Builder osType(OsType osType) {
+ this.osType = osType;
+ return this;
+ }
+
+ public Builder cpuHotplug(boolean cpuHotplug) {
+ this.cpuHotplug = cpuHotplug;
+ return this;
+ }
+
+ public Builder cpuHotunplug(boolean cpuHotunplug) {
+ this.cpuHotunplug = cpuHotunplug;
+ return this;
+ }
+
+ public Builder ramHotplug(boolean ramHotplug) {
+ this.ramHotplug = ramHotplug;
+ return this;
+ }
+
+ public Builder ramHotunplug(boolean ramHotunplug) {
+ this.ramHotunplug = ramHotunplug;
+ return this;
+ }
+
+ public Builder nicHotplug(boolean nicHotplug) {
+ this.nicHotplug = nicHotplug;
+ return this;
+ }
+
+ public Builder nicHotunplug(boolean nicHotunplug) {
+ this.nicHotunplug = nicHotunplug;
+ return this;
+ }
+
+ public Builder discVirtioHotplug(boolean discVirtioHotplug) {
+ this.discVirtioHotplug = discVirtioHotplug;
+ return this;
+ }
+
+ public Builder discVirtioHotunplug(boolean discVirtioHotunplug) {
+ this.discVirtioHotunplug = discVirtioHotunplug;
+ return this;
+ }
+
+ public UpdatePayload build() {
+ return UpdatePayload.create(snapshotId, description, name, bootable, osType, cpuHotplug, cpuHotunplug, ramHotplug, ramHotunplug, nicHotplug, nicHotunplug, discVirtioHotplug, discVirtioHotunplug);
+ }
+ }
+
+ }
+
+ @AutoValue
+ public abstract static class RollbackPayload {
+
+ public abstract String snapshotId();
+
+ public abstract String storageId();
+
+ public static RollbackPayload create(String snapshotId, String storageId) {
+ return new AutoValue_Snapshot_Request_RollbackPayload(snapshotId, storageId);
+ }
+
+ public static class Builder {
+
+ private String snapshotId;
+
+ private String storageId;
+
+ public Builder snapshotId(String snapshotId) {
+ this.snapshotId = snapshotId;
+ return this;
+ }
+
+ public Builder storageId(String storageId) {
+ this.storageId = storageId;
+ return this;
+ }
+
+ public RollbackPayload build() {
+ return RollbackPayload.create(snapshotId, storageId);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/features/SnapshotApi.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/features/SnapshotApi.java b/profitbricks/src/main/java/org/jclouds/profitbricks/features/SnapshotApi.java
new file mode 100644
index 0000000..3faa386
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/features/SnapshotApi.java
@@ -0,0 +1,87 @@
+/*
+ * 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.snapshot.CreateSnapshotRequestBinder;
+import org.jclouds.profitbricks.binder.snapshot.RollbackSnapshotRequestBinder;
+import org.jclouds.profitbricks.binder.snapshot.UpdateSnapshotRequestBinder;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
+import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
+import org.jclouds.profitbricks.http.parser.snapshot.SnapshotResponseHandler;
+import org.jclouds.profitbricks.http.parser.snapshot.SnapshotListResponseHandler;
+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 SnapshotApi {
+
+ @POST
+ @Named("snapshot:getall")
+ @Payload("<ws:getAllSnapshots/>")
+ @XMLResponseParser(SnapshotListResponseHandler.class)
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<Snapshot> getAllSnapshots();
+
+ @POST
+ @Named("snapshot:get")
+ @Payload("<ws:getSnapshot><snapshotId>{snapshotId}</snapshotId></ws:getSnapshot>")
+ @XMLResponseParser(SnapshotResponseHandler.class)
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ Snapshot getSnapshot(@PayloadParam("snapshotId") String identifier);
+
+ @POST
+ @Named("snapshot:create")
+ @MapBinder(CreateSnapshotRequestBinder.class)
+ @XMLResponseParser(SnapshotResponseHandler.class)
+ Snapshot createSnapshot(@PayloadParam("snapshot") Snapshot.Request.CreatePayload payload);
+
+ @POST
+ @Named("snapshot:update")
+ @MapBinder(UpdateSnapshotRequestBinder.class)
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String updateSnapshot(@PayloadParam("snapshot") Snapshot.Request.UpdatePayload payload);
+
+ @POST
+ @Named("snapshot:delete")
+ @Payload("<ws:deleteSnapshot><snapshotId>{id}</snapshotId></ws:deleteSnapshot>")
+ @Fallback(Fallbacks.FalseOnNotFoundOr404.class)
+ boolean deleteSnapshot(@PayloadParam("id") String id);
+
+ @POST
+ @Named("snapshot:rollback")
+ @MapBinder(RollbackSnapshotRequestBinder.class)
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String rollbackSnapshot(@PayloadParam("snapshot") Snapshot.Request.RollbackPayload payload);
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/BaseSnapshotResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/BaseSnapshotResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/BaseSnapshotResponseHandler.java
new file mode 100644
index 0000000..0fa7fd6
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/BaseSnapshotResponseHandler.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.snapshot;
+
+import java.util.Date;
+import org.jclouds.date.DateCodec;
+import org.jclouds.date.DateCodecFactory;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.OsType;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
+
+public abstract class BaseSnapshotResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
+
+ protected Snapshot.Builder builder;
+
+ protected final DateCodec dateCodec;
+
+ BaseSnapshotResponseHandler(DateCodecFactory dateCodec) {
+ this.dateCodec = dateCodec.iso8601();
+ this.builder = Snapshot.builder();
+ }
+
+ protected final Date textToIso8601Date() {
+ return dateCodec.toDate(textToStringValue());
+ }
+
+ @Override
+ protected void setPropertyOnEndTag(String qName) {
+ if ("snapshotId".equals(qName))
+ builder.id(textToStringValue());
+ else if ("snapshotName".equals(qName))
+ builder.name(textToStringValue());
+ else if ("snapshotSize".equals(qName))
+ builder.size(textToFloatValue());
+ else if ("osType".equals(qName))
+ builder.osType(OsType.fromValue(textToStringValue()));
+ else if ("location".equals(qName))
+ builder.location(Location.fromId(textToStringValue()));
+ else if ("description".equals(qName))
+ builder.description(qName);
+ else if ("bootable".equals(qName))
+ builder.bootable(textToBooleanValue());
+ else if ("cpuHotPlug".equals(qName))
+ builder.cpuHotPlug(textToBooleanValue());
+ else if ("cpuHotUnPlug".equals(qName))
+ builder.cpuHotUnPlug(textToBooleanValue());
+ else if ("ramHotPlug".equals(qName))
+ builder.ramHotPlug(textToBooleanValue());
+ else if ("ramHotUnPlug".equals(qName))
+ builder.ramHotUnPlug(textToBooleanValue());
+ else if ("nicHotPlug".equals(qName))
+ builder.nicHotPlug(textToBooleanValue());
+ else if ("nicHotUnPlug".equals(qName))
+ builder.nicHotUnPlug(textToBooleanValue());
+ else if ("discVirtioHotPlug".equals(qName))
+ builder.discVirtioHotPlug(textToBooleanValue());
+ else if ("discVirtioHotUnPlug".equals(qName))
+ builder.discVirtioHotUnPlug(textToBooleanValue());
+ else if ("provisioningState".equals(qName))
+ builder.state(ProvisioningState.fromValue(textToStringValue()));
+ else if ("creationTimestamp".equals(qName))
+ builder.creationTime(textToIso8601Date());
+ else if ("modificationTimestamp".equals(qName))
+ builder.lastModificationTime(textToIso8601Date());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandler.java
new file mode 100644
index 0000000..ae7a355
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandler.java
@@ -0,0 +1,52 @@
+/*
+ * 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.snapshot;
+
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.xml.sax.SAXException;
+
+import java.util.List;
+import org.jclouds.date.DateCodecFactory;
+
+public class SnapshotListResponseHandler extends BaseSnapshotResponseHandler<List<Snapshot>> {
+
+ private final List<Snapshot> snapshots;
+
+ @Inject
+ SnapshotListResponseHandler(DateCodecFactory dateCodec) {
+ super(dateCodec);
+ this.snapshots = Lists.newArrayList();
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ setPropertyOnEndTag(qName);
+ if ("return".equals(qName)) {
+ snapshots.add(builder.build());
+ builder = Snapshot.builder();
+ }
+ clearTextBuffer();
+ }
+
+ @Override
+ public List<Snapshot> getResult() {
+ return snapshots;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandler.java
new file mode 100644
index 0000000..84316f8
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandler.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.snapshot;
+
+import com.google.inject.Inject;
+import org.jclouds.date.DateCodecFactory;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.xml.sax.SAXException;
+
+public class SnapshotResponseHandler extends BaseSnapshotResponseHandler<Snapshot> {
+
+ private boolean done = false;
+
+ @Inject
+ SnapshotResponseHandler(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 Snapshot getResult() {
+ return builder.build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinderTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinderTest.java
new file mode 100644
index 0000000..dda2ed6
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/CreateSnapshotRequestBinderTest.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.snapshot;
+
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+@Test(groups = "unit", testName = "CreateSnapshotRequestBinderTest")
+public class CreateSnapshotRequestBinderTest {
+
+ @Test
+ public void testCreatePayload() {
+ CreateSnapshotRequestBinder binder = new CreateSnapshotRequestBinder();
+
+ Snapshot.Request.CreatePayload payload = Snapshot.Request.CreatePayload.create("123-1233-1324", "describingthesnapshot", "snapshotname");
+
+ String actual = binder.createPayload(payload);
+ assertNotNull(actual, "Binder returned null payload");
+ assertEquals(expectedPayload, actual);
+ }
+
+ private final String expectedPayload
+ = (" <ws:createSnapshot>\n"
+ + "<request>\n"
+ + "<storageId>123-1233-1324</storageId>\n"
+ + "<description>describing the snapshot</description>\n"
+ + "<snapshotName>snapshot name</snapshotName>\n"
+ + "</request>\n"
+ + "</ws:createSnapshot>").replaceAll("\\s+", "");
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinderTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinderTest.java
new file mode 100644
index 0000000..206cd79
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/RollbackSnapshotRequestBinderTest.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.snapshot;
+
+import org.jclouds.profitbricks.domain.Snapshot;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "RollbackSnapshotRequestBinderTest")
+public class RollbackSnapshotRequestBinderTest {
+
+ @Test
+ public void testRollbackPayload() {
+ RollbackSnapshotRequestBinder binder = new RollbackSnapshotRequestBinder();
+
+ Snapshot.Request.RollbackPayload payload = Snapshot.Request.rollbackBuilder()
+ .snapshotId("snapshot-id")
+ .storageId("storage-id")
+ .build();
+
+ String actual = binder.createPayload(payload);
+ assertNotNull(actual, "Binder returned null payload");
+ assertEquals(expectedPayload, actual);
+ }
+
+ private final String expectedPayload = "<ws:rollbackSnapshot>"
+ + "<request>"
+ + "<snapshotId>snapshot-id</snapshotId>"
+ + "<storageId>storage-id</storageId>"
+ + "</request>"
+ + "</ws:rollbackSnapshot>".replaceAll("\\s", "");
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinderTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinderTest.java
new file mode 100644
index 0000000..3acb8e1
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/snapshot/UpdateSnapshotRequestBinderTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.snapshot;
+
+import org.jclouds.profitbricks.domain.OsType;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+@Test(groups = "unit", testName = "UpdateSnapshotRequestBinderTest")
+public class UpdateSnapshotRequestBinderTest {
+
+ @Test
+ public void testUpdatePayload() {
+ UpdateSnapshotRequestBinder binder = new UpdateSnapshotRequestBinder();
+
+ Snapshot.Request.UpdatePayload payload = Snapshot.Request.UpdatePayload.create("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh", "description", "snapshot-name", true, OsType.LINUX, true, true, true, true, true, true, true, true);
+
+ String actual = binder.createPayload(payload);
+ assertNotNull(actual, "Binder returned null payload");
+ assertEquals(expectedPayload, actual);
+
+ }
+
+ private final String expectedPayload
+ = "<ws:updateSnapshot>"
+ + "<request>"
+ + "<snapshotId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</snapshotId>"
+ + "<description>description</description>"
+ + "<snapshotName>snapshot-name</snapshotName>"
+ + "<bootable>true</bootable>"
+ + "<osType>LINUX</osType>"
+ + "<cpuHotPlug>true</cpuHotPlug>"
+ + "<cpuHotUnPlug>true</cpuHotUnPlug>"
+ + "<ramHotPlug>true</ramHotPlug>"
+ + "<ramHotUnPlug>true</ramHotUnPlug>"
+ + "<nicHotPlug>true</nicHotPlug>"
+ + "<nicHotUnPlug>true</nicHotUnPlug>"
+ + "<discVirtioHotPlug>true</discVirtioHotPlug>"
+ + "<discVirtioHotUnPlug>true</discVirtioHotUnPlug>"
+ + "</request>"
+ + "</ws:updateSnapshot>".replaceAll("\\s", "");
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
index f69fc02..857a8ff 100644
--- a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
@@ -136,5 +136,38 @@ public class ProvisioningStatusPollingPredicateTest extends BaseProfitBricksMock
server.shutdown();
}
}
+
+ @Test
+ public void testSnapshotPredicate() throws Exception{
+ MockWebServer server = mockWebServer();
+
+ byte[] payloadInProcess = payloadFromResource("/snapshot/snapshot-state-inprocess.xml");
+ byte[] payloadAvailable = payloadFromResource("/snapshot/snapshot.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<String> waitUntilAvailable = Predicates2.retry(
+ new ProvisioningStatusPollingPredicate(pbApi, ProvisioningStatusAware.SNAPSHOT, ProvisioningState.AVAILABLE),
+ 30l, 1l, TimeUnit.SECONDS);
+
+ String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+ try {
+ waitUntilAvailable.apply(id);
+ ProvisioningState finalState = pbApi.snapshotApi().getSnapshot(id).state();
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertEquals(finalState, ProvisioningState.AVAILABLE);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiLiveTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiLiveTest.java
new file mode 100644
index 0000000..957555b
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiLiveTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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 com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.domain.OsType;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Storage;
+import org.jclouds.util.Predicates2;
+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 org.testng.annotations.AfterClass;
+
+@Test(groups = "live", testName = "SnapshotApiLiveTest", singleThreaded = true)
+public class SnapshotApiLiveTest extends BaseProfitBricksLiveTest {
+
+ protected Predicate<String> snapshotWaitingPredicate;
+ private String snapshotId;
+ private String storageId;
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+
+ initializeWaitPredicate();
+
+ List<Storage> storages = api.storageApi().getAllStorages();
+ assertFalse(storages.isEmpty(), "Must atleast have 1 storage available for snapshot testing.");
+
+ storageId = Iterables.getFirst(storages, null).id();
+ }
+
+ @Test
+ public void testCreateSnapshot() {
+ Snapshot snapshot = api.snapshotApi().createSnapshot(Snapshot.Request.CreatePayload.create(storageId, "my description", "test snapshot"));
+
+ assertNotNull(snapshot);
+
+ snapshotWaitingPredicate.apply(snapshot.id());
+
+ snapshotId = snapshot.id();
+ }
+
+ @Test(dependsOnMethods = "testCreateSnapshot")
+ public void testGetAllSnapshots() {
+ List<Snapshot> snapshots = api.snapshotApi().getAllSnapshots();
+
+ assertNotNull(snapshots);
+ assertTrue(snapshots.size() > 0);
+ }
+
+ @Test(dependsOnMethods = "testCreateSnapshot")
+ public void testGetSnapshot() {
+ Snapshot snapshot = api.snapshotApi().getSnapshot(snapshotId);
+
+ assertNotNull(snapshot);
+ assertEquals(snapshot.id(), snapshotId);
+ }
+
+ @Test(dependsOnMethods = "testCreateSnapshot")
+ public void testUpdateSnapshot() {
+
+ String newName = "new name";
+
+ api.snapshotApi().updateSnapshot(Snapshot.Request.updatingBuilder()
+ .snapshotId(snapshotId)
+ .description("new description")
+ .name(newName)
+ .bootable(true)
+ .osType(OsType.LINUX)
+ .cpuHotplug(true)
+ .cpuHotunplug(true)
+ .discVirtioHotplug(true)
+ .discVirtioHotunplug(true)
+ .nicHotplug(true)
+ .nicHotunplug(true)
+ .ramHotplug(true)
+ .ramHotunplug(true)
+ .build());
+
+ Snapshot snapshot = api.snapshotApi().getSnapshot(snapshotId);
+
+ assertNotNull(snapshot);
+ assertEquals(snapshot.name(), newName);
+ }
+
+ @Test(dependsOnMethods = "testCreateSnapshot")
+ public void testRollbackSnapshot() {
+ String result = api.snapshotApi().rollbackSnapshot(Snapshot.Request.RollbackPayload.create(snapshotId, storageId));
+
+ assertNotNull(result);
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void testDeleteSnapshot() {
+ boolean result = api.snapshotApi().deleteSnapshot(snapshotId);
+
+ assertTrue(result);
+ }
+
+ private void initializeWaitPredicate() {
+ this.snapshotWaitingPredicate = Predicates2.retry(
+ new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.SNAPSHOT, ProvisioningState.AVAILABLE),
+ 2l * 60l, 2l, TimeUnit.SECONDS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java
new file mode 100644
index 0000000..80342b0
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java
@@ -0,0 +1,262 @@
+/*
+ * 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 com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.OsType;
+import org.jclouds.profitbricks.domain.Snapshot;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
+import org.testng.Assert;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Mock tests for the {@link org.jclouds.profitbricks.features.DataCenterApi} class
+ */
+@Test(groups = "unit", testName = "SnapshotApiMockTest")
+public class SnapshotApiMockTest extends BaseProfitBricksMockTest {
+
+ @Test
+ public void testGetAllSnapshots() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshots.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ try {
+ List<Snapshot> snapshots = api.getAllSnapshots();
+ assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllSnapshots/>");
+ assertNotNull(snapshots);
+ assertEquals(snapshots.size(), 2);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetAllSnapshotsReturning404() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ try {
+ List<Snapshot> snapshots = api.getAllSnapshots();
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertTrue(snapshots.isEmpty());
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+
+ String content = "<ws:getSnapshot><snapshotId>" + id + "</snapshotId></ws:getSnapshot>";
+
+ try {
+ Snapshot snapshot = api.getSnapshot(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(snapshot);
+ assertEquals(snapshot.id(), id);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetNonExistingSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String id = "random-non-existing-id";
+ try {
+ Snapshot snapshot = api.getSnapshot(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertNull(snapshot);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testCreateSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-create.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String storageId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+
+ String content = "<ws:createSnapshot>"
+ + "<request>"
+ + "<storageId>" + storageId + "</storageId>"
+ + "<description>description</description>"
+ + "<snapshotName>snapshot-name</snapshotName>"
+ + "</request>"
+ + "</ws:createSnapshot>";
+
+ try {
+ Snapshot snapshot = api.createSnapshot(
+ Snapshot.Request.creatingBuilder()
+ .storageId(storageId)
+ .description("description")
+ .name("snapshot-name")
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(snapshot.id());
+ assertEquals(snapshot.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
+
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testUpdateSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-update.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String snapshotId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+
+ String content = "<ws:updateSnapshot>"
+ + "<request>"
+ + "<snapshotId>" + snapshotId + "</snapshotId>"
+ + "<description>description</description>"
+ + "<snapshotName>snapshot-name</snapshotName>"
+ + "<bootable>false</bootable>"
+ + "<osType>LINUX</osType>"
+ + "<cpuHotPlug>false</cpuHotPlug>"
+ + "<cpuHotUnPlug>false</cpuHotUnPlug>"
+ + "<ramHotPlug>false</ramHotPlug>"
+ + "<ramHotUnPlug>false</ramHotUnPlug>"
+ + "<nicHotPlug>false</nicHotPlug>"
+ + "<nicHotUnPlug>false</nicHotUnPlug>"
+ + "<discVirtioHotPlug>false</discVirtioHotPlug>"
+ + "<discVirtioHotUnPlug>false</discVirtioHotUnPlug>"
+ + "</request>"
+ + "</ws:updateSnapshot>";
+
+ try {
+ String requestId = api.updateSnapshot(Snapshot.Request.updatingBuilder()
+ .snapshotId(snapshotId)
+ .name("snapshot-name")
+ .description("description")
+ .osType(OsType.LINUX)
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testDeleteSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-delete.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String snapshotId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+ String content = "<ws:deleteSnapshot><snapshotId>" + snapshotId + "</snapshotId></ws:deleteSnapshot>";
+
+ try {
+ boolean result = api.deleteSnapshot(snapshotId);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertTrue(result);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testDeleteNonExistingSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String id = "random-non-existing-id";
+ try {
+ boolean result = api.deleteSnapshot(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ Assert.assertFalse(result);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testRollbackSnapshot() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-rollback.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ SnapshotApi api = pbApi.snapshotApi();
+
+ String snapshotId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+ String storageId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+
+ String content = "<ws:rollbackSnapshot><request><snapshotId>" + snapshotId + "</snapshotId><storageId>" + storageId + "</storageId></request></ws:rollbackSnapshot>";
+ try {
+ String result = api.rollbackSnapshot(Snapshot.Request.rollbackBuilder()
+ .snapshotId(snapshotId)
+ .storageId(storageId)
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(result);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandlerTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandlerTest.java
new file mode 100644
index 0000000..38dfa1e
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotListResponseHandlerTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.snapshot;
+
+import com.google.common.collect.Lists;
+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.Location;
+import org.jclouds.profitbricks.domain.OsType;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Snapshot;
+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 = "SnapshotListResponseHandlerTest")
+public class SnapshotListResponseHandlerTest extends BaseResponseHandlerTest<List<Snapshot>> {
+
+ @Override
+ protected ParseSax<List<Snapshot>> createParser() {
+ return factory.create(injector.getInstance(SnapshotListResponseHandler.class));
+ }
+
+ protected DateCodecFactory createDateParser() {
+ return injector.getInstance(DateCodecFactory.class);
+ }
+
+ @Test
+ public void testParseResponseFromGetSnapshot() {
+ ParseSax<List<Snapshot>> parser = createParser();
+
+ List<Snapshot> actual = parser.parse(payloadFromResource("/snapshot/snapshots.xml"));
+ assertNotNull(actual);
+
+ DateCodec dateParser = createDateParser().iso8601();
+
+ List<Snapshot> expected = Lists.newArrayList();
+
+ expected.add(Snapshot.builder()
+ .id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
+ .description("description")
+ .size(1024)
+ .name("snapshot01")
+ .state(ProvisioningState.AVAILABLE)
+ .bootable(true)
+ .osType(OsType.LINUX)
+ .cpuHotPlug(true)
+ .cpuHotUnPlug(true)
+ .discVirtioHotPlug(true)
+ .discVirtioHotUnPlug(true)
+ .ramHotPlug(true)
+ .ramHotUnPlug(true)
+ .nicHotPlug(true)
+ .nicHotUnPlug(true)
+ .location(Location.US_LAS)
+ .creationTime(dateParser.toDate("2015-01-26T07:09:23.138Z"))
+ .lastModificationTime(dateParser.toDate("2015-01-26T07:09:23.138Z"))
+ .build());
+
+ expected.add(Snapshot.builder()
+ .id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy")
+ .description("description")
+ .size(1024)
+ .name("snapshot02")
+ .state(ProvisioningState.AVAILABLE)
+ .bootable(true)
+ .osType(OsType.LINUX)
+ .cpuHotPlug(true)
+ .cpuHotUnPlug(true)
+ .discVirtioHotPlug(true)
+ .discVirtioHotUnPlug(true)
+ .ramHotPlug(true)
+ .ramHotUnPlug(true)
+ .nicHotPlug(true)
+ .nicHotUnPlug(true)
+ .location(Location.US_LAS)
+ .creationTime(dateParser.toDate("2015-01-26T07:09:23.138Z"))
+ .lastModificationTime(dateParser.toDate("2015-01-26T07:09:23.138Z"))
+ .build());
+
+ assertEquals(actual, expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandlerTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandlerTest.java
new file mode 100644
index 0000000..9928e92
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/snapshot/SnapshotResponseHandlerTest.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.snapshot;
+
+import org.jclouds.date.DateCodec;
+import org.jclouds.date.DateCodecFactory;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.OsType;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Snapshot;
+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 = "ServerResponseHandlerTest")
+public class SnapshotResponseHandlerTest extends BaseResponseHandlerTest<Snapshot> {
+
+ @Override
+ protected ParseSax<Snapshot> createParser() {
+ return factory.create(injector.getInstance(SnapshotResponseHandler.class));
+ }
+
+ protected DateCodecFactory createDateParser() {
+ return injector.getInstance(DateCodecFactory.class);
+ }
+
+ @Test
+ public void testParseResponseFromGetSnapshot() {
+ ParseSax<Snapshot> parser = createParser();
+
+ Snapshot actual = parser.parse(payloadFromResource("/snapshot/snapshot.xml"));
+ assertNotNull(actual, "Parsed content returned null");
+
+ DateCodec dateParser = createDateParser().iso8601();
+
+ Snapshot expected = Snapshot.builder()
+ .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh")
+ .description("description")
+ .size(1024)
+ .name("snapshot01")
+ .state(ProvisioningState.AVAILABLE)
+ .bootable(true)
+ .osType(OsType.LINUX)
+ .cpuHotPlug(true)
+ .cpuHotUnPlug(true)
+ .discVirtioHotPlug(true)
+ .discVirtioHotUnPlug(true)
+ .ramHotPlug(true)
+ .ramHotUnPlug(true)
+ .nicHotPlug(true)
+ .nicHotUnPlug(true)
+ .location(Location.US_LAS)
+ .creationTime(dateParser.toDate("2015-01-26T07:09:23.138Z"))
+ .lastModificationTime(dateParser.toDate("2015-01-26T07:09:23.138Z"))
+ .build();
+
+ assertEquals(actual, expected);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshot-create.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshot-create.xml b/profitbricks/src/test/resources/snapshot/snapshot-create.xml
new file mode 100644
index 0000000..06a537d
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshot-create.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:createSnapshotReturn xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>12345678</requestId>
+ <snapshotId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</snapshotId>
+ </return>
+ </ns2:createSnapshotReturn>
+ </S:Body>
+</S:Envelope>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshot-delete.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshot-delete.xml b/profitbricks/src/test/resources/snapshot/snapshot-delete.xml
new file mode 100644
index 0000000..45bf1a3
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshot-delete.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:deleteSnapshotResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>123456789</requestId>
+ </return>
+ </ns2:deleteSnapshotResponse>
+ </S:Body>
+</S:Envelope>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshot-rollback.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshot-rollback.xml b/profitbricks/src/test/resources/snapshot/snapshot-rollback.xml
new file mode 100644
index 0000000..661ce21
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshot-rollback.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:rollbackSnapshotResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>1234567890</requestId>
+ <dataCenterId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</dataCenterId>
+ <dataCenterVersion>1</dataCenterVersion>
+ </return>
+ </ns2:rollbackSnapshotResponse>
+ </S:Body>
+</S:Envelope>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshot-state-inprocess.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshot-state-inprocess.xml b/profitbricks/src/test/resources/snapshot/snapshot-state-inprocess.xml
new file mode 100644
index 0000000..9f8acff
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshot-state-inprocess.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:getSnapshotResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <snapshotId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</snapshotId>
+ <description>description</description>
+ <snapshotSize>1024</snapshotSize>
+ <snapshotName>snapshot01</snapshotName>
+ <provisioningState>INPROCESS</provisioningState>
+ <bootable>true</bootable>
+ <osType>LINUX</osType>
+ <cpuHotPlug>true</cpuHotPlug>
+ <cpuHotUnPlug>true</cpuHotUnPlug>
+ <discVirtioHotPlug>true</discVirtioHotPlug>
+ <discVirtioHotUnPlug>true</discVirtioHotUnPlug>
+ <ramHotPlug>true</ramHotPlug>
+ <ramHotUnPlug>true</ramHotUnPlug>
+ <nicHotPlug>true</nicHotPlug>
+ <nicHotUnPlug>true</nicHotUnPlug>
+ <creationTimestamp>2015-01-26T07:09:23.138Z</creationTimestamp>
+ <modificationTimestamp>2015-01-26T07:09:23.138Z</modificationTimestamp>
+ <location>us/las</location>
+ </return>
+ </ns2:getSnapshotResponse>
+ </S:Body>
+</S:Envelope>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshot-update.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshot-update.xml b/profitbricks/src/test/resources/snapshot/snapshot-update.xml
new file mode 100644
index 0000000..028cce0
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshot-update.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:updateSnapshotResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>12345678</requestId>
+ </return>
+ </ns2:updateSnapshotResponse>
+ </S:Body>
+</S:Envelope>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshot.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshot.xml b/profitbricks/src/test/resources/snapshot/snapshot.xml
new file mode 100644
index 0000000..d406be1
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshot.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:getSnapshotResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <snapshotId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</snapshotId>
+ <description>description</description>
+ <snapshotSize>1024</snapshotSize>
+ <snapshotName>snapshot01</snapshotName>
+ <provisioningState>AVAILABLE</provisioningState>
+ <bootable>true</bootable>
+ <osType>LINUX</osType>
+ <cpuHotPlug>true</cpuHotPlug>
+ <cpuHotUnPlug>true</cpuHotUnPlug>
+ <discVirtioHotPlug>true</discVirtioHotPlug>
+ <discVirtioHotUnPlug>true</discVirtioHotUnPlug>
+ <ramHotPlug>true</ramHotPlug>
+ <ramHotUnPlug>true</ramHotUnPlug>
+ <nicHotPlug>true</nicHotPlug>
+ <nicHotUnPlug>true</nicHotUnPlug>
+ <creationTimestamp>2015-01-26T07:09:23.138Z</creationTimestamp>
+ <modificationTimestamp>2015-01-26T07:09:23.138Z</modificationTimestamp>
+ <location>us/las</location>
+ </return>
+ </ns2:getSnapshotResponse>
+ </S:Body>
+</S:Envelope>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/47a5f5d0/profitbricks/src/test/resources/snapshot/snapshots.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/snapshot/snapshots.xml b/profitbricks/src/test/resources/snapshot/snapshots.xml
new file mode 100644
index 0000000..d59826a
--- /dev/null
+++ b/profitbricks/src/test/resources/snapshot/snapshots.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:getAllSnapshotsResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <snapshotId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</snapshotId>
+ <description>description</description>
+ <snapshotSize>1024</snapshotSize>
+ <snapshotName>snapshot01</snapshotName>
+ <provisioningState>AVAILABLE</provisioningState>
+ <bootable>true</bootable>
+ <osType>LINUX</osType>
+ <cpuHotPlug>true</cpuHotPlug>
+ <cpuHotUnPlug>true</cpuHotUnPlug>
+ <discVirtioHotPlug>true</discVirtioHotPlug>
+ <discVirtioHotUnPlug>true</discVirtioHotUnPlug>
+ <ramHotPlug>true</ramHotPlug>
+ <ramHotUnPlug>true</ramHotUnPlug>
+ <nicHotPlug>true</nicHotPlug>
+ <nicHotUnPlug>true</nicHotUnPlug>
+ <creationTimestamp>2015-01-26T07:09:23.138Z</creationTimestamp>
+ <modificationTimestamp>2015-01-26T07:09:23.138Z</modificationTimestamp>
+ <location>us/las</location>
+ </return>
+ <return>
+ <snapshotId>qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy</snapshotId>
+ <description>description</description>
+ <snapshotSize>1024</snapshotSize>
+ <snapshotName>snapshot02</snapshotName>
+ <provisioningState>AVAILABLE</provisioningState>
+ <bootable>true</bootable>
+ <osType>LINUX</osType>
+ <cpuHotPlug>true</cpuHotPlug>
+ <cpuHotUnPlug>true</cpuHotUnPlug>
+ <discVirtioHotPlug>true</discVirtioHotPlug>
+ <discVirtioHotUnPlug>true</discVirtioHotUnPlug>
+ <ramHotPlug>true</ramHotPlug>
+ <ramHotUnPlug>true</ramHotUnPlug>
+ <nicHotPlug>true</nicHotPlug>
+ <nicHotUnPlug>true</nicHotUnPlug>
+ <creationTimestamp>2015-01-26T07:09:23.138Z</creationTimestamp>
+ <modificationTimestamp>2015-01-26T07:09:23.138Z</modificationTimestamp>
+ <location>us/las</location>
+ </return>
+ </ns2:getAllSnapshotsResponse>
+ </S:Body>
+</S:Envelope>
[2/3] jclouds-labs git commit: Profitbricks IpBlock API
Posted by na...@apache.org.
Profitbricks IpBlock API
Conflicts:
profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/f5605dd4
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/f5605dd4
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/f5605dd4
Branch: refs/heads/master
Commit: f5605dd4546ee38125e38bded8673b2791b68ad7
Parents: 47a5f5d
Author: jasminSPC <ja...@stackpointcloud.com>
Authored: Tue Mar 3 22:46:34 2015 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Sun Mar 8 21:15:43 2015 +0100
----------------------------------------------------------------------
.../jclouds/profitbricks/ProfitBricksApi.java | 5 +
.../jclouds/profitbricks/domain/IpBlock.java | 125 ++++++++++++
.../profitbricks/features/IpBlockApi.java | 80 ++++++++
.../ipblock/BaseIpBlockResponseHandler.java | 68 +++++++
.../ipblock/IpBlockListResponseHandler.java | 62 ++++++
.../parser/ipblock/IpBlockResponseHandler.java | 64 ++++++
.../publicip/BasePublicIpResponseHandler.java | 38 ++++
.../publicip/PublicIpListResponseHandler.java | 51 +++++
.../features/IpBlockApiLiveTest.java | 92 +++++++++
.../features/IpBlockApiMockTest.java | 200 +++++++++++++++++++
.../ipblock/IpBlockListResponseHandlerTest.java | 77 +++++++
.../ipblock/IpBlockResponseHandlerTest.java | 63 ++++++
.../test/resources/ipblock/ipblock-addtonic.xml | 12 ++
.../test/resources/ipblock/ipblock-release.xml | 10 +
.../resources/ipblock/ipblock-removefromnic.xml | 12 ++
.../test/resources/ipblock/ipblock-reserve.xml | 13 ++
.../src/test/resources/ipblock/ipblock.xml | 18 ++
.../src/test/resources/ipblock/ipblocks.xml | 30 +++
18 files changed, 1020 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java b/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
index af7a31d..34309bf 100644
--- a/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
@@ -20,6 +20,7 @@ import java.io.Closeable;
import org.jclouds.profitbricks.features.DataCenterApi;
import org.jclouds.profitbricks.features.FirewallApi;
import org.jclouds.profitbricks.features.ImageApi;
+import org.jclouds.profitbricks.features.IpBlockApi;
import org.jclouds.profitbricks.features.NicApi;
import org.jclouds.profitbricks.features.ServerApi;
import org.jclouds.profitbricks.features.SnapshotApi;
@@ -48,4 +49,8 @@ public interface ProfitBricksApi extends Closeable {
@Delegate
SnapshotApi snapshotApi();
+
+ @Delegate
+ IpBlockApi ipBlockApi();
+
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/domain/IpBlock.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/domain/IpBlock.java b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/IpBlock.java
new file mode 100644
index 0000000..47741ff
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/IpBlock.java
@@ -0,0 +1,125 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.jclouds.javax.annotation.Nullable;
+
+@AutoValue
+public abstract class IpBlock {
+
+ public abstract String id();
+
+ public abstract Location location();
+
+ public abstract List<PublicIp> publicIps();
+
+ public abstract List<String> ips();
+
+ public static IpBlock create(String id, Location location, List<PublicIp> publicIps, List<String> ips) {
+ return new AutoValue_IpBlock(id, location, publicIps, ips != null ? ImmutableList.copyOf(ips) : ImmutableList.<String>of());
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+
+ private String id;
+ private Location location;
+ private List<PublicIp> publicIps;
+ private List<String> ips;
+
+ public Builder id(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder location(Location location) {
+ this.location = location;
+ return this;
+ }
+
+ public Builder publicIps(List<PublicIp> publicIps) {
+ this.publicIps = publicIps;
+ return this;
+ }
+
+ public Builder ips(List<String> ips) {
+ this.ips = ips;
+ return this;
+ }
+
+ public IpBlock build() {
+ return IpBlock.create(id, location, publicIps, ips);
+ }
+
+ public Builder fromIpBlock(IpBlock in) {
+ return this.id(in.id()).location(in.location()).publicIps(in.publicIps()).ips(in.ips());
+ }
+
+ }
+
+ @AutoValue
+ public abstract static class PublicIp {
+
+ public abstract String ip();
+
+ @Nullable
+ public abstract String nicId();
+
+ public static PublicIp create(String ip, String nicId) {
+ return new AutoValue_IpBlock_PublicIp(ip, nicId);
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Builder toBuilder() {
+ return builder().fromPublicIp(this);
+ }
+
+ public static final class Builder {
+
+ private String ip;
+ private String nicId;
+
+ public Builder ip(String ip) {
+ this.ip = ip;
+ return this;
+ }
+
+ public Builder nicId(String nicId) {
+ this.nicId = nicId;
+ return this;
+ }
+
+ public PublicIp build() {
+ return PublicIp.create(ip, nicId);
+ }
+
+ public Builder fromPublicIp(PublicIp in) {
+ return this.ip(in.ip()).nicId(in.nicId());
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/features/IpBlockApi.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/features/IpBlockApi.java b/profitbricks/src/main/java/org/jclouds/profitbricks/features/IpBlockApi.java
new file mode 100644
index 0000000..a81293e
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/features/IpBlockApi.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.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.IpBlock;
+import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
+import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
+import org.jclouds.profitbricks.http.parser.ipblock.IpBlockListResponseHandler;
+import org.jclouds.profitbricks.http.parser.ipblock.IpBlockResponseHandler;
+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 IpBlockApi {
+
+ @POST
+ @Named("publicipblock:get")
+ @Payload("<ws:getPublicIpBlock><blockId>{id}</blockId></ws:getPublicIpBlock>")
+ @XMLResponseParser(IpBlockResponseHandler.class)
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ IpBlock getIpBlock(@PayloadParam("id") String identifier);
+
+ @POST
+ @Named("publicipblock:getall")
+ @Payload("<ws:getAllPublicIpBlocks />")
+ @XMLResponseParser(IpBlockListResponseHandler.class)
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<IpBlock> getAllIpBlock();
+
+ @POST
+ @Named("publicipblock:reserve")
+ @Payload("<ws:reservePublicIpBlock><request><blockSize>{blockSize}</blockSize><location>{location}</location></request></ws:reservePublicIpBlock>")
+ @XMLResponseParser(IpBlockResponseHandler.class)
+ IpBlock reservePublicIpBlock(@PayloadParam("blockSize") String blockSize, @PayloadParam("location") String location);
+
+ @POST
+ @Named("publicipblock:addip")
+ @Payload("<ws:addPublicIpToNic><ip>{ip}</ip><nicId>{nicid}</nicId></ws:addPublicIpToNic>")
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String addPublicIpToNic(@PayloadParam("ip") String ip, @PayloadParam("nicid") String nicid);
+
+ @POST
+ @Named("publicipblock:removeip")
+ @Payload("<ws:removePublicIpFromNic><ip>{ip}</ip><nicId>{nicid}</nicId></ws:removePublicIpFromNic>")
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String removePublicIpFromNic(@PayloadParam("ip") String ip, @PayloadParam("nicid") String nicid);
+
+ @POST
+ @Named("publicipblock:releaseblock")
+ @Payload("<ws:releasePublicIpBlock><blockId>{blockid}</blockId></ws:releasePublicIpBlock>")
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String releasePublicIpBlock(@PayloadParam("blockid") String blockid);
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/BaseIpBlockResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/BaseIpBlockResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/BaseIpBlockResponseHandler.java
new file mode 100644
index 0000000..a4af29f
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/BaseIpBlockResponseHandler.java
@@ -0,0 +1,68 @@
+/*
+ * 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.ipblock;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
+import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public abstract class BaseIpBlockResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
+
+ protected final PublicIpListResponseHandler publicIpListResponseHandler;
+ protected final List<IpBlock.PublicIp> publicIps = Lists.newArrayList();
+ protected List<String> ips;
+
+ protected IpBlock.Builder builder;
+ protected boolean usePublicIpListParser = false;
+
+ BaseIpBlockResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
+ this.builder = IpBlock.builder();
+ this.publicIpListResponseHandler = publicIpListResponseHandler;
+ ips = Lists.newArrayList();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if ("publicIps".equals(qName))
+ usePublicIpListParser = true;
+ if (usePublicIpListParser)
+ publicIpListResponseHandler.startElement(uri, localName, qName, attributes);
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) {
+ if (usePublicIpListParser)
+ publicIpListResponseHandler.characters(ch, start, length);
+ else
+ super.characters(ch, start, length);
+ }
+
+ @Override
+ protected void setPropertyOnEndTag(String qName) {
+ if ("blockId".equals(qName))
+ builder.id(textToStringValue());
+ else if ("location".equals(qName))
+ builder.location(Location.fromId(textToStringValue()));
+ else if ("ips".equals(qName))
+ ips.add(textToStringValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandler.java
new file mode 100644
index 0000000..c56f0ea
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandler.java
@@ -0,0 +1,62 @@
+/*
+ * 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.ipblock;
+
+import autovalue.shaded.com.google.common.common.collect.Lists;
+import com.google.inject.Inject;
+import java.util.List;
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
+import org.xml.sax.SAXException;
+
+public class IpBlockListResponseHandler extends BaseIpBlockResponseHandler<List<IpBlock>> {
+
+ private final List<IpBlock> ipBlocks;
+
+ @Inject
+ IpBlockListResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
+ super(publicIpListResponseHandler);
+ ipBlocks = Lists.newArrayList();
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if (usePublicIpListParser)
+ publicIpListResponseHandler.endElement(uri, localName, qName);
+ else {
+ setPropertyOnEndTag(qName);
+ if ("return".equals(qName)) {
+ ipBlocks.add(builder
+ .publicIps(publicIpListResponseHandler.getResult())
+ .build());
+ publicIpListResponseHandler.reset();
+ builder = IpBlock.builder();
+ }
+ clearTextBuffer();
+ }
+
+ if ("publicIps".equals(qName))
+ usePublicIpListParser = false;
+
+ }
+
+ @Override
+ public List<IpBlock> getResult() {
+ return ipBlocks;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandler.java
new file mode 100644
index 0000000..307db14
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandler.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.http.parser.ipblock;
+
+import com.google.inject.Inject;
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
+import org.xml.sax.SAXException;
+
+public class IpBlockResponseHandler extends BaseIpBlockResponseHandler<IpBlock> {
+
+ private boolean done = false;
+
+ @Inject
+ IpBlockResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
+ super(publicIpListResponseHandler);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if (done)
+ return;
+
+ if (usePublicIpListParser)
+ publicIpListResponseHandler.endElement(uri, localName, qName);
+ else {
+ setPropertyOnEndTag(qName);
+ if ("return".equals(qName)) {
+ done = true;
+ builder.publicIps(publicIpListResponseHandler.getResult());
+ builder.ips(ips);
+ }
+ clearTextBuffer();
+ }
+
+ if ("publicIps".equals(qName))
+ usePublicIpListParser = false;
+ }
+
+ @Override
+ public void reset() {
+ this.builder = IpBlock.builder();
+ }
+
+ @Override
+ public IpBlock getResult() {
+ return builder.build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/BasePublicIpResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/BasePublicIpResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/BasePublicIpResponseHandler.java
new file mode 100644
index 0000000..8561aad
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/BasePublicIpResponseHandler.java
@@ -0,0 +1,38 @@
+/*
+ * 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.publicip;
+
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
+
+public abstract class BasePublicIpResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
+
+ protected IpBlock.PublicIp.Builder builder;
+
+ BasePublicIpResponseHandler() {
+ this.builder = IpBlock.PublicIp.builder();
+ }
+
+ @Override
+ protected void setPropertyOnEndTag(String qName) {
+ if ("ip".equals(qName))
+ builder.ip(textToStringValue());
+ else if ("nicId".equals(qName))
+ builder.nicId(textToStringValue());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/PublicIpListResponseHandler.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/PublicIpListResponseHandler.java b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/PublicIpListResponseHandler.java
new file mode 100644
index 0000000..c68e7e6
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/http/parser/publicip/PublicIpListResponseHandler.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.publicip;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
+import org.xml.sax.SAXException;
+
+public class PublicIpListResponseHandler extends BasePublicIpResponseHandler<List<PublicIp>> {
+
+ private List<PublicIp> publicIps;
+
+ PublicIpListResponseHandler() {
+ this.publicIps = Lists.newArrayList();
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ setPropertyOnEndTag(qName);
+
+ if ("publicIps".equals(qName))
+ publicIps.add(builder.build());
+ clearTextBuffer();
+ }
+
+ @Override
+ public void reset() {
+ this.publicIps = Lists.newArrayList();
+ }
+
+ @Override
+ public List<PublicIp> getResult() {
+ return publicIps;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiLiveTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiLiveTest.java
new file mode 100644
index 0000000..227cfc7
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiLiveTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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 com.google.common.collect.Iterables;
+import java.util.List;
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.Nic;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "live", testName = "IpBlockApiLiveTest", singleThreaded = true)
+public class IpBlockApiLiveTest extends BaseProfitBricksLiveTest {
+
+ private String nicid;
+ private IpBlock newIpBlock;
+
+ @Override
+ public void initialize() {
+ super.initialize();
+
+ List<Nic> nics = api.nicApi().getAllNics();
+
+ assertFalse(nics.isEmpty(), "At least one NIC is requred to test IpBlocks");
+
+ Nic nic = Iterables.getFirst(nics, null);
+
+ nicid = nic.id();
+ }
+
+ @Test
+ public void testReservePublicIpBlock() {
+ newIpBlock = api.ipBlockApi().reservePublicIpBlock("2", Location.US_LAS.value());
+
+ assertNotNull(newIpBlock);
+ assertNotNull(newIpBlock.ips());
+ assertFalse(newIpBlock.ips().isEmpty());
+ }
+
+ @Test
+ public void testGetAllIpBlocks() {
+ List<IpBlock> ipBlocks = api.ipBlockApi().getAllIpBlock();
+
+ assertNotNull(ipBlocks);
+ assertFalse(ipBlocks.isEmpty());
+ }
+
+ @Test(dependsOnMethods = "testReservePublicIpBlock")
+ public void testGetOneIpBlock() {
+ IpBlock ipBlock = api.ipBlockApi().getIpBlock(newIpBlock.id());
+
+ assertNotNull(ipBlock);
+ }
+
+ @Test(dependsOnMethods = "testReservePublicIpBlock")
+ public void testAddPublicIpToNic() {
+ String requestId = api.ipBlockApi().addPublicIpToNic(newIpBlock.ips().get(0), nicid);
+
+ assertNotNull(requestId);
+ }
+
+ @Test(dependsOnMethods = "testAddPublicIpToNic")
+ public void testRemovePublicIpFromNic() {
+ String requestId = api.ipBlockApi().removePublicIpFromNic(newIpBlock.ips().get(0), nicid);
+
+ assertNotNull(requestId);
+ }
+
+ @Test(dependsOnMethods = "testRemovePublicIpFromNic")
+ public void testReleasePublicIpBlock() {
+ String requestId = api.ipBlockApi().releasePublicIpBlock(newIpBlock.id());
+
+ assertNotNull(requestId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java
new file mode 100644
index 0000000..b0d3356
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java
@@ -0,0 +1,200 @@
+/*
+ * 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 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.IpBlock;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "IpBlockApiMockTest")
+public class IpBlockApiMockTest extends BaseProfitBricksMockTest {
+
+ @Test
+ public void testGetOneIpBlock() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
+
+ String content = "<ws:getPublicIpBlock><blockId>" + id + "</blockId></ws:getPublicIpBlock>";
+
+ try {
+ IpBlock ipBlock = api.getIpBlock(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(ipBlock);
+ assertEquals(ipBlock.id(), id);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetNonExisingIpBlock() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
+
+ try {
+ IpBlock ipBlock = api.getIpBlock(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertNull(ipBlock);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetAllIpBlock() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblocks.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ try {
+ List<IpBlock> ipBlocks = api.getAllIpBlock();
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertNotNull(ipBlocks);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetAllIpBlockReturning404() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ try {
+ List<IpBlock> ipBlocks = api.getAllIpBlock();
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertTrue(ipBlocks.isEmpty());
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testReservePublicIpBlock() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-reserve.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ String blockSize = "2";
+ Location location = Location.US_LAS;
+
+ String content = "<ws:reservePublicIpBlock><request><blockSize>" + blockSize + "</blockSize><location>" + location.value() + "</location></request></ws:reservePublicIpBlock>";
+ try {
+ IpBlock ipBlock = api.reservePublicIpBlock(blockSize, location.value());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(ipBlock);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testAddPublicIpToNic() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-addtonic.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ String ip = "2";
+ String nicid = "nicid";
+
+ String content = "<ws:addPublicIpToNic><ip>" + ip + "</ip><nicId>" + nicid + "</nicId></ws:addPublicIpToNic>";
+ try {
+ String requestId = api.addPublicIpToNic(ip, nicid);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testRemovePublicIpFromNic() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-removefromnic.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ String ip = "2";
+ String nicid = "nicid";
+
+ String content = "<ws:removePublicIpFromNic><ip>" + ip + "</ip><nicId>" + nicid + "</nicId></ws:removePublicIpFromNic>";
+ try {
+ String requestId = api.removePublicIpFromNic(ip, nicid);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testReleasePublicIpBlock() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-release.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ IpBlockApi api = pbApi.ipBlockApi();
+
+ String blockid = "2";
+
+ String content = "<ws:releasePublicIpBlock><blockId>" + blockid + "</blockId></ws:releasePublicIpBlock>";
+ try {
+ String requestId = api.releasePublicIpBlock(blockid);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandlerTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandlerTest.java
new file mode 100644
index 0000000..49dbaba
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockListResponseHandlerTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.ipblock;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
+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 = "IpBlockListResponseHandlerTest")
+public class IpBlockListResponseHandlerTest extends BaseResponseHandlerTest<List<IpBlock>> {
+
+ @Override
+ protected ParseSax<List<IpBlock>> createParser() {
+ return factory.create(injector.getInstance(IpBlockListResponseHandler.class));
+ }
+
+ @Test
+ public void testParseResponseFromGetAllIpBlock() {
+ ParseSax<List<IpBlock>> parser = createParser();
+
+ List<IpBlock> actual = parser.parse(payloadFromResource("/ipblock/ipblocks.xml"));
+ assertNotNull(actual, "Parsed content returned null");
+
+ List<IpBlock> expected = ImmutableList.<IpBlock>of(
+ IpBlock.builder()
+ .id("block-id")
+ .location(Location.US_LAS)
+ .publicIps(ImmutableList.<PublicIp>of(
+ PublicIp.builder()
+ .ip("1.1")
+ .nicId("nic-id")
+ .build(),
+ PublicIp.builder()
+ .ip("1.2")
+ .nicId("nic-id")
+ .build()))
+ .build(),
+ IpBlock.builder()
+ .id("block-id")
+ .location(Location.US_LAS)
+ .publicIps(ImmutableList.<PublicIp>of(
+ PublicIp.builder()
+ .ip("2.1")
+ .nicId("nic-id")
+ .build(),
+ PublicIp.builder()
+ .ip("2.2")
+ .nicId("nic-id")
+ .build()))
+ .build()
+ );
+
+ assertEquals(actual, expected);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandlerTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandlerTest.java
new file mode 100644
index 0000000..54f48dc
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ipblock/IpBlockResponseHandlerTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.ipblock;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.IpBlock;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
+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 = "IpBlockResponseHandlerTest")
+public class IpBlockResponseHandlerTest extends BaseResponseHandlerTest<IpBlock> {
+
+ @Override
+ protected ParseSax<IpBlock> createParser() {
+ return factory.create(injector.getInstance(IpBlockResponseHandler.class));
+ }
+
+ @Test
+ public void testParseResponseFromGetIpBlock() {
+ ParseSax<IpBlock> parser = createParser();
+
+ IpBlock actual = parser.parse(payloadFromResource("/ipblock/ipblock.xml"));
+ assertNotNull(actual, "Parsed content returned null");
+ List<String> emptyIpList = Lists.newArrayList();
+
+ IpBlock expected = IpBlock.builder()
+ .id("qwertyui-qwer-qwer-qwer-qwertyyuiiop")
+ .location(Location.US_LAS)
+ .publicIps(ImmutableList.<PublicIp>of(
+ PublicIp.builder()
+ .ip("ip")
+ .nicId("nic-id")
+ .build(),
+ PublicIp.builder()
+ .ip("ip")
+ .nicId("nic-id")
+ .build()))
+ .ips(emptyIpList)
+ .build();
+ assertEquals(actual, expected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/resources/ipblock/ipblock-addtonic.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/ipblock/ipblock-addtonic.xml b/profitbricks/src/test/resources/ipblock/ipblock-addtonic.xml
new file mode 100644
index 0000000..a9c1974
--- /dev/null
+++ b/profitbricks/src/test/resources/ipblock/ipblock-addtonic.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:addPublicIpToNicResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>request-id</requestId>
+ <dataCenterId>datacenter-id</dataCenterId>
+ <dataCenterVersion>datacenter-version</dataCenterVersion>
+ </return>
+ </ns2:addPublicIpToNicResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/resources/ipblock/ipblock-release.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/ipblock/ipblock-release.xml b/profitbricks/src/test/resources/ipblock/ipblock-release.xml
new file mode 100644
index 0000000..a9f22bf
--- /dev/null
+++ b/profitbricks/src/test/resources/ipblock/ipblock-release.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:releasePublicIpBlockResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>request-id</requestId>
+ </return>
+ </ns2:releasePublicIpBlockResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/resources/ipblock/ipblock-removefromnic.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/ipblock/ipblock-removefromnic.xml b/profitbricks/src/test/resources/ipblock/ipblock-removefromnic.xml
new file mode 100644
index 0000000..a9c1974
--- /dev/null
+++ b/profitbricks/src/test/resources/ipblock/ipblock-removefromnic.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:addPublicIpToNicResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>request-id</requestId>
+ <dataCenterId>datacenter-id</dataCenterId>
+ <dataCenterVersion>datacenter-version</dataCenterVersion>
+ </return>
+ </ns2:addPublicIpToNicResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/resources/ipblock/ipblock-reserve.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/ipblock/ipblock-reserve.xml b/profitbricks/src/test/resources/ipblock/ipblock-reserve.xml
new file mode 100644
index 0000000..863e9ff
--- /dev/null
+++ b/profitbricks/src/test/resources/ipblock/ipblock-reserve.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:reservePublicIpBlockResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>request-id</requestId>
+ <blockId>block-id</blockId>
+ <location>us/las</location>
+ <ips>ip</ips>
+ </return>
+ </ns2:reservePublicIpBlockResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/resources/ipblock/ipblock.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/ipblock/ipblock.xml b/profitbricks/src/test/resources/ipblock/ipblock.xml
new file mode 100644
index 0000000..2dd54f2
--- /dev/null
+++ b/profitbricks/src/test/resources/ipblock/ipblock.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:getAllPublicIpBlocksResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <blockId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</blockId>
+ <location>us/las</location>
+ <publicIps>
+ <ip>ip</ip>
+ <nicId>nic-id</nicId>
+ </publicIps>
+ <publicIps>
+ <ip>ip</ip>
+ </publicIps>
+ </return>
+ </ns2:getAllPublicIpBlocksResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f5605dd4/profitbricks/src/test/resources/ipblock/ipblocks.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/ipblock/ipblocks.xml b/profitbricks/src/test/resources/ipblock/ipblocks.xml
new file mode 100644
index 0000000..4e436e1
--- /dev/null
+++ b/profitbricks/src/test/resources/ipblock/ipblocks.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:getAllPublicIpBlocksResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <blockId>block-id</blockId>
+ <location>us/las</location>
+ <publicIps>
+ <ip>1.1</ip>
+ <nicId>nic-id</nicId>
+ </publicIps>
+ <publicIps>
+ <ip>1.2</ip>
+ <nicId>nic-id</nicId>
+ </publicIps>
+ </return>
+ <return>
+ <blockId>block-id</blockId>
+ <location>us/las</location>
+ <publicIps>
+ <ip>2.1</ip>
+ </publicIps>
+ <publicIps>
+ <ip>2.2</ip>
+ <nicId>nic-id</nicId>
+ </publicIps>
+ </return>
+ </ns2:getAllPublicIpBlocksResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
[3/3] jclouds-labs git commit: Profitbricks Drives API
Posted by na...@apache.org.
Profitbricks Drives API
Conflicts:
profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/e6305c26
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/e6305c26
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/e6305c26
Branch: refs/heads/master
Commit: e6305c26e5583ada7711e515b2c76bb7aecbf2a2
Parents: f5605dd
Author: jasminSPC <ja...@stackpointcloud.com>
Authored: Tue Mar 3 23:04:46 2015 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Sun Mar 8 21:20:23 2015 +0100
----------------------------------------------------------------------
.../jclouds/profitbricks/ProfitBricksApi.java | 3 +
.../drive/AddRomDriveToServerRequestBinder.java | 45 +++++++++++
.../org/jclouds/profitbricks/domain/Drive.java | 70 +++++++++++++++++
.../jclouds/profitbricks/domain/Location.java | 1 +
.../profitbricks/features/DrivesApi.java | 51 ++++++++++++
.../AddRomDriveToServerRequestBinderTest.java | 49 ++++++++++++
.../features/DrivesApiLiveTest.java | 72 +++++++++++++++++
.../features/DrivesApiMockTest.java | 81 ++++++++++++++++++++
.../image/ImageListResponseHandlerTest.java | 6 +-
.../src/test/resources/drives/drives-add.xml | 12 +++
.../src/test/resources/drives/drives-remove.xml | 12 +++
11 files changed, 399 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java b/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
index 34309bf..12da7ea 100644
--- a/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
@@ -18,6 +18,7 @@ package org.jclouds.profitbricks;
import java.io.Closeable;
import org.jclouds.profitbricks.features.DataCenterApi;
+import org.jclouds.profitbricks.features.DrivesApi;
import org.jclouds.profitbricks.features.FirewallApi;
import org.jclouds.profitbricks.features.ImageApi;
import org.jclouds.profitbricks.features.IpBlockApi;
@@ -53,4 +54,6 @@ public interface ProfitBricksApi extends Closeable {
@Delegate
IpBlockApi ipBlockApi();
+ @Delegate
+ DrivesApi drivesApi();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/main/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinder.java b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinder.java
new file mode 100644
index 0000000..3a931ab
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinder.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.drive;
+
+import static java.lang.String.format;
+import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
+import org.jclouds.profitbricks.domain.Drive;
+
+public class AddRomDriveToServerRequestBinder extends BaseProfitBricksRequestBinder<Drive.Request.AddRomDriveToServerPayload> {
+
+ private final StringBuilder requestBuilder;
+
+ AddRomDriveToServerRequestBinder() {
+ super("payload");
+ this.requestBuilder = new StringBuilder(128);
+ }
+
+ @Override
+ protected String createPayload(Drive.Request.AddRomDriveToServerPayload payload) {
+ requestBuilder.append("<ws:addRomDriveToServer>")
+ .append("<request>")
+ .append(format("<imageId>%s</imageId>", payload.imageId()))
+ .append(format("<serverId>%s</serverId>", payload.serverId()))
+ .append(formatIfNotEmpty("<deviceNumber>%s</deviceNumber>", payload.deviceNumber()))
+ .append("</request>")
+ .append("</ws:addRomDriveToServer>");
+
+ return requestBuilder.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Drive.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Drive.java b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Drive.java
new file mode 100644
index 0000000..08add2a
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Drive.java
@@ -0,0 +1,70 @@
+/*
+ * 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 Drive {
+
+ public static final class Request {
+
+ @AutoValue
+ public abstract static class AddRomDriveToServerPayload {
+
+ public abstract String serverId();
+
+ public abstract String imageId();
+
+ public abstract String deviceNumber();
+
+ public static AddRomDriveToServerPayload create(String serverId, String storageId, String deviceNumber) {
+ return new AutoValue_Drive_Request_AddRomDriveToServerPayload(serverId, storageId, deviceNumber);
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private String serverId;
+ private String imageId;
+ private String deviceNumber;
+
+ public Builder serverId(String serverId) {
+ this.serverId = serverId;
+ return this;
+ }
+
+ public Builder storageId(String storageId) {
+ this.imageId = storageId;
+ return this;
+ }
+
+ public Builder deviceNumber(String deviceNumber) {
+ this.deviceNumber = deviceNumber;
+ return this;
+ }
+
+ public AddRomDriveToServerPayload build() {
+ return AddRomDriveToServerPayload.create(serverId, imageId, deviceNumber);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java
index 0354bf4..3dd888d 100644
--- a/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/domain/Location.java
@@ -21,6 +21,7 @@ public enum Location {
DE_FKB("de/fkb"),
DE_FRA("de/fra"),
US_LAS("us/las"),
+ US_LAS_DEV("us/lasdev"),
UNRECOGNIZED("unknown");
private final String id;
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/main/java/org/jclouds/profitbricks/features/DrivesApi.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/main/java/org/jclouds/profitbricks/features/DrivesApi.java b/profitbricks/src/main/java/org/jclouds/profitbricks/features/DrivesApi.java
new file mode 100644
index 0000000..70f70a0
--- /dev/null
+++ b/profitbricks/src/main/java/org/jclouds/profitbricks/features/DrivesApi.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.features;
+
+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.http.filters.BasicAuthentication;
+import org.jclouds.profitbricks.binder.drive.AddRomDriveToServerRequestBinder;
+import org.jclouds.profitbricks.domain.Drive;
+import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
+import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
+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 DrivesApi {
+
+ @POST
+ @Named("drives:add")
+ @MapBinder(AddRomDriveToServerRequestBinder.class)
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String addRomDriveToServer(@PayloadParam("payload") Drive.Request.AddRomDriveToServerPayload payload);
+
+ @POST
+ @Named("drives:remove")
+ @Payload("<ws:removeRomDriveFromServer><imageId>{imageid}</imageId><serverId>{serverid}</serverId></ws:removeRomDriveFromServer>")
+ @XMLResponseParser(RequestIdOnlyResponseHandler.class)
+ String removeRomDriveFromServer(@PayloadParam("imageid") String imageid, @PayloadParam("serverid") String serverid);
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/test/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinderTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinderTest.java
new file mode 100644
index 0000000..13fb7f1
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/binder/drive/AddRomDriveToServerRequestBinderTest.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.binder.drive;
+
+import org.jclouds.profitbricks.domain.Drive;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "AddRomDriveToServerRequestBinderTest")
+public class AddRomDriveToServerRequestBinderTest {
+
+ @Test
+ public void testAddRomDriveToServerPayload() {
+ AddRomDriveToServerRequestBinder binder = new AddRomDriveToServerRequestBinder();
+
+ Drive.Request.AddRomDriveToServerPayload payload = Drive.Request.AddRomDriveToServerPayload.builder()
+ .serverId("server-id")
+ .storageId("image-id")
+ .deviceNumber("device-number")
+ .build();
+
+ String actual = binder.createPayload(payload);
+ assertEquals(expectedPayload, actual);
+ }
+
+ private final String expectedPayload
+ = (" <ws:addRomDriveToServer>"
+ + " <request>"
+ + " <imageId>image-id</imageId>"
+ + " <serverId>server-id</serverId>"
+ + " <deviceNumber>device-number</deviceNumber>"
+ + " </request>"
+ + " </ws:addRomDriveToServer>").replaceAll("\\s+", "");
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java
new file mode 100644
index 0000000..aacc314
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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 autovalue.shaded.com.google.common.common.collect.Iterables;
+import java.util.List;
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.domain.Drive;
+import org.jclouds.profitbricks.domain.Image;
+import org.jclouds.profitbricks.domain.Server;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "live", testName = "DrivesApiLiveTest", singleThreaded = true)
+public class DrivesApiLiveTest extends BaseProfitBricksLiveTest {
+
+ public String serverId;
+ public String imageId;
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+
+ List<Server> servers = api.serverApi().getAllServers();
+ assertFalse(servers.isEmpty(), "At least one server is required to run drives test.");
+
+ Server server = Iterables.getFirst(servers, null);
+ assertNotNull(server);
+
+ this.serverId = server.id();
+
+ List<Image> images = api.imageApi().getAllImages();
+ assertFalse(images.isEmpty(), "At least one image is required to run drives test.");
+
+ Image image = Iterables.getFirst(images, null);
+ assertNotNull(image);
+
+ this.imageId = image.id();
+ }
+
+ @Test
+ public void addRomDriveToServerTest() {
+ String requestId = api.drivesApi().addRomDriveToServer(Drive.Request.AddRomDriveToServerPayload.builder()
+ .serverId(serverId)
+ .storageId("05cadf29-6c12-11e4-beeb-52540066fee9")
+ .deviceNumber("0")
+ .build());
+ assertNotNull(requestId);
+ }
+
+ @Test (dependsOnMethods = "addRomDriveToServerTest")
+ public void removeRomDriveFromServerTest() {
+ String requestId = api.drivesApi().removeRomDriveFromServer(imageId, serverId);
+
+ assertNotNull(requestId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java
new file mode 100644
index 0000000..d55676d
--- /dev/null
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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 com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.Drive;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "DrivesApiMockTest")
+public class DrivesApiMockTest extends BaseProfitBricksMockTest {
+
+ @Test
+ public void addRomDriveToServerTest() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/drives/drives-add.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ DrivesApi api = pbApi.drivesApi();
+
+ String content = "<ws:addRomDriveToServer>"
+ + "<request>"
+ + "<imageId>image-id</imageId>"
+ + "<serverId>server-id</serverId>"
+ + "<deviceNumber>device-number</deviceNumber>"
+ + "</request>"
+ + "</ws:addRomDriveToServer>";
+ try {
+ String requestId = api.addRomDriveToServer(Drive.Request.AddRomDriveToServerPayload.builder()
+ .serverId("server-id")
+ .storageId("image-id")
+ .deviceNumber("device-number")
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void removeRomDriveFromServerTest() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/drives/drives-remove.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ DrivesApi api = pbApi.drivesApi();
+
+ String content = "<ws:removeRomDriveFromServer>"
+ + "<imageId>image-id</imageId>"
+ + "<serverId>server-id</serverId>"
+ + "</ws:removeRomDriveFromServer>";
+ try {
+ String requestId = api.removeRomDriveFromServer("image-id", "server-id");
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java
index 4827138..7d0cb88 100644
--- a/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java
+++ b/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java
@@ -91,7 +91,7 @@ public class ImageListResponseHandlerTest extends BaseResponseHandlerTest<List<I
.name("Debian-jessie-prerelease-server-2015-01-01")
.size(2048f)
.type(Image.Type.HDD)
- .location(Location.UNRECOGNIZED)
+ .location(Location.US_LAS_DEV)
.isNicHotPlug(true)
.isNicHotUnPlug(true)
.osType(OsType.LINUX)
@@ -110,7 +110,7 @@ public class ImageListResponseHandlerTest extends BaseResponseHandlerTest<List<I
.name("Fedora-19-server-2015-01-01")
.size(2048f)
.type(Image.Type.HDD)
- .location(Location.UNRECOGNIZED)
+ .location(Location.US_LAS_DEV)
.isNicHotPlug(true)
.isNicHotUnPlug(true)
.osType(OsType.LINUX)
@@ -129,7 +129,7 @@ public class ImageListResponseHandlerTest extends BaseResponseHandlerTest<List<I
.name("Ubuntu-12.04-LTS-server-2015-01-01")
.size(2048f)
.type(Image.Type.HDD)
- .location(Location.UNRECOGNIZED)
+ .location(Location.US_LAS_DEV)
.isNicHotPlug(true)
.isNicHotUnPlug(true)
.osType(OsType.LINUX)
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/test/resources/drives/drives-add.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/drives/drives-add.xml b/profitbricks/src/test/resources/drives/drives-add.xml
new file mode 100644
index 0000000..752f8f3
--- /dev/null
+++ b/profitbricks/src/test/resources/drives/drives-add.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:addRomDriveToServerResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>request-id</requestId>
+ <dataCenterId>datacenter-id</dataCenterId>
+ <dataCenterVersion>datacenter-version</dataCenterVersion>
+ </return>
+ </ns2:addRomDriveToServerResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/e6305c26/profitbricks/src/test/resources/drives/drives-remove.xml
----------------------------------------------------------------------
diff --git a/profitbricks/src/test/resources/drives/drives-remove.xml b/profitbricks/src/test/resources/drives/drives-remove.xml
new file mode 100644
index 0000000..ccfd400
--- /dev/null
+++ b/profitbricks/src/test/resources/drives/drives-remove.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+ <S:Body>
+ <ns2:removeRomDriveFromServerResponse xmlns:ns2="http://ws.api.profitbricks.com/">
+ <return>
+ <requestId>request-id</requestId>
+ <dataCenterId>datacenter-id</dataCenterId>
+ <dataCenterVersion>datacenter-version</dataCenterVersion>
+ </return>
+ </ns2:removeRomDriveFromServerResponse>
+ </S:Body>
+</S:Envelope>
\ No newline at end of file