mirror of https://github.com/apache/jclouds.git
Profitbricks Drives API
Conflicts: profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
This commit is contained in:
parent
af93f3b68f
commit
f58675e93d
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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+", "");
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue