mirror of https://github.com/apache/jclouds.git
JCLOUDS-702: JClouds ProfitBricks provider - Storage API
This commit is contained in:
parent
ee24ddb2b4
commit
2a219a9948
|
@ -21,6 +21,7 @@ import java.io.Closeable;
|
|||
import org.jclouds.profitbricks.features.DataCenterApi;
|
||||
import org.jclouds.profitbricks.features.ImageApi;
|
||||
import org.jclouds.profitbricks.features.ServerApi;
|
||||
import org.jclouds.profitbricks.features.StorageApi;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
public interface ProfitBricksApi extends Closeable {
|
||||
|
@ -33,4 +34,7 @@ public interface ProfitBricksApi extends Closeable {
|
|||
|
||||
@Delegate
|
||||
ServerApi serverApi();
|
||||
|
||||
@Delegate
|
||||
StorageApi storageApi();
|
||||
}
|
||||
|
|
|
@ -53,29 +53,29 @@ public class ProfitBricksApiMetadata extends BaseHttpApiMetadata<ProfitBricksApi
|
|||
public static class Builder extends BaseHttpApiMetadata.Builder<ProfitBricksApi, Builder> {
|
||||
|
||||
protected Builder() {
|
||||
id("profitbricks")
|
||||
.name("ProfitBricks API")
|
||||
.identityName("API Username")
|
||||
.credentialName("API Password")
|
||||
.documentation(URI.create("https://www.profitbricks.com/sites/default/files/profitbricks_api_1_3.pdf"))
|
||||
.defaultEndpoint("https://api.profitbricks.com/1.3")
|
||||
.version("1.3")
|
||||
// .view(ComputeServiceContext.class)
|
||||
.defaultProperties(ProfitBricksApiMetadata.defaultProperties())
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(
|
||||
ProfitBricksHttpApiModule.class,
|
||||
ProfitBricksHttpCommandExecutorServiceModule.class
|
||||
));
|
||||
id("profitbricks")
|
||||
.name("ProfitBricks API")
|
||||
.identityName("API Username")
|
||||
.credentialName("API Password")
|
||||
.documentation(URI.create("https://www.profitbricks.com/sites/default/files/profitbricks_api_1_3.pdf"))
|
||||
.defaultEndpoint("https://api.profitbricks.com/1.3")
|
||||
.version("1.3")
|
||||
// .view(ComputeServiceContext.class)
|
||||
.defaultProperties(ProfitBricksApiMetadata.defaultProperties())
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(
|
||||
ProfitBricksHttpApiModule.class,
|
||||
ProfitBricksHttpCommandExecutorServiceModule.class
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfitBricksApiMetadata build() {
|
||||
return new ProfitBricksApiMetadata(this);
|
||||
return new ProfitBricksApiMetadata(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder self() {
|
||||
return this;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,23 +44,23 @@ public class ProfitBricksProviderMetadata extends BaseProviderMetadata {
|
|||
public static class Builder extends BaseProviderMetadata.Builder {
|
||||
|
||||
protected Builder() {
|
||||
id("profitbricks")
|
||||
.name("ProfitBricks Cloud Compute 2.0")
|
||||
.homepage(URI.create("http://www.profitbricks.com"))
|
||||
.console(URI.create("https://my.profitbricks.com/dashboard/dcdr2/"))
|
||||
.linkedServices("profitbricks")
|
||||
.apiMetadata(new ProfitBricksApiMetadata());
|
||||
id("profitbricks")
|
||||
.name("ProfitBricks Cloud Compute 2.0")
|
||||
.homepage(URI.create("http://www.profitbricks.com"))
|
||||
.console(URI.create("https://my.profitbricks.com/dashboard/dcdr2/"))
|
||||
.linkedServices("profitbricks")
|
||||
.apiMetadata(new ProfitBricksApiMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfitBricksProviderMetadata build() {
|
||||
return new ProfitBricksProviderMetadata(this);
|
||||
return new ProfitBricksProviderMetadata(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder fromProviderMetadata(ProviderMetadata in) {
|
||||
super.fromProviderMetadata(in);
|
||||
return this;
|
||||
super.fromProviderMetadata(in);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ public abstract class BaseProfitBricksRequestBinder<T> implements MapBinder {
|
|||
|
||||
protected abstract String createPayload(T payload);
|
||||
|
||||
protected String formatIfNotEmpty(String pattern, Object param) {
|
||||
return Strings.isNullOrEmpty(nullableToString( param )) ? "" : String.format(pattern, param);
|
||||
protected static String formatIfNotEmpty(String pattern, Object param) {
|
||||
return Strings.isNullOrEmpty(nullableToString(param)) ? "" : String.format(pattern, param);
|
||||
}
|
||||
|
||||
protected String nullableToString(Object object) {
|
||||
protected static String nullableToString(Object object) {
|
||||
return object == null ? "" : object.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@ public class CreateDataCenterRequestBinder extends BaseProfitBricksRequestBinder
|
|||
@Override
|
||||
protected String createPayload(DataCenter.Request.CreatePayload payload) {
|
||||
requestBuilder.append("<ws:createDataCenter>")
|
||||
.append("<request>")
|
||||
.append(format("<dataCenterName>%s</dataCenterName>", payload.name()))
|
||||
.append(format("<location>%s</location>", payload.location().value()))
|
||||
.append("</request>")
|
||||
.append("</ws:createDataCenter>");
|
||||
.append("<request>")
|
||||
.append(format("<dataCenterName>%s</dataCenterName>", payload.name()))
|
||||
.append(format("<location>%s</location>", payload.location().value()))
|
||||
.append("</request>")
|
||||
.append("</ws:createDataCenter>");
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,32 +25,32 @@ public class CreateServerRequestBinder extends BaseProfitBricksRequestBinder<Ser
|
|||
protected final StringBuilder requestBuilder;
|
||||
|
||||
CreateServerRequestBinder() {
|
||||
super( "server" );
|
||||
this.requestBuilder = new StringBuilder( 128 * 4 );
|
||||
super("server");
|
||||
this.requestBuilder = new StringBuilder(128 * 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload( Server.Request.CreatePayload payload ) {
|
||||
requestBuilder.append( "<ws:createServer>" )
|
||||
.append( "<request>" )
|
||||
.append( format( "<dataCenterId>%s</dataCenterId>", payload.dataCenterId() ) )
|
||||
.append( format( "<cores>%s</cores>", payload.cores() ) )
|
||||
.append( format( "<ram>%s</ram>", payload.ram() ) )
|
||||
.append( formatIfNotEmpty( "<serverName>%s</serverName>", payload.name() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId() ) )
|
||||
.append( formatIfNotEmpty( "<internetAccess>%s</internetAccess>", payload.hasInternetAccess() ) )
|
||||
.append( formatIfNotEmpty( "<lanId>%s</lanId>", payload.lanId() ) )
|
||||
.append( formatIfNotEmpty( "<osType>%s</osType>", payload.osType() ) )
|
||||
.append( formatIfNotEmpty( "<availabilityZone>%s</availabilityZone>", payload.availabilityZone() ) )
|
||||
.append( formatIfNotEmpty( "<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug() ) )
|
||||
.append( "</request>" )
|
||||
.append( "</ws:createServer>" );
|
||||
protected String createPayload(Server.Request.CreatePayload payload) {
|
||||
requestBuilder.append("<ws:createServer>")
|
||||
.append("<request>")
|
||||
.append(format("<dataCenterId>%s</dataCenterId>", payload.dataCenterId()))
|
||||
.append(format("<cores>%s</cores>", payload.cores()))
|
||||
.append(format("<ram>%s</ram>", payload.ram()))
|
||||
.append(formatIfNotEmpty("<serverName>%s</serverName>", payload.name()))
|
||||
.append(formatIfNotEmpty("<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId()))
|
||||
.append(formatIfNotEmpty("<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId()))
|
||||
.append(formatIfNotEmpty("<internetAccess>%s</internetAccess>", payload.hasInternetAccess()))
|
||||
.append(formatIfNotEmpty("<lanId>%s</lanId>", payload.lanId()))
|
||||
.append(formatIfNotEmpty("<osType>%s</osType>", payload.osType()))
|
||||
.append(formatIfNotEmpty("<availabilityZone>%s</availabilityZone>", payload.availabilityZone()))
|
||||
.append(formatIfNotEmpty("<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug()))
|
||||
.append(formatIfNotEmpty("<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug()))
|
||||
.append(formatIfNotEmpty("<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug()))
|
||||
.append(formatIfNotEmpty("<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug()))
|
||||
.append(formatIfNotEmpty("<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug()))
|
||||
.append(formatIfNotEmpty("<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug()))
|
||||
.append("</request>")
|
||||
.append("</ws:createServer>");
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,31 +25,31 @@ public class UpdateServerRequestBinder extends BaseProfitBricksRequestBinder<Ser
|
|||
protected final StringBuilder requestBuilder;
|
||||
|
||||
UpdateServerRequestBinder() {
|
||||
super( "server" );
|
||||
this.requestBuilder = new StringBuilder( 128 * 4 );
|
||||
super("server");
|
||||
this.requestBuilder = new StringBuilder(128 * 4);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload( Server.Request.UpdatePayload payload ) {
|
||||
requestBuilder.append( "<ws:updateServer>" )
|
||||
.append( "<request>" )
|
||||
.append( format( "<serverId>%s</serverId>", payload.id() ) )
|
||||
.append( format( "<cores>%s</cores>", payload.cores() ) )
|
||||
.append( format( "<ram>%s</ram>", payload.ram() ) )
|
||||
.append( formatIfNotEmpty( "<serverName>%s</serverName>", payload.name() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId() ) )
|
||||
.append( formatIfNotEmpty( "<osType>%s</osType>", payload.osType() ) )
|
||||
.append( formatIfNotEmpty( "<availabilityZone>%s</availabilityZone>", payload.availabilityZone() ) )
|
||||
.append( formatIfNotEmpty( "<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug() ) )
|
||||
.append( "</request>" )
|
||||
.append( "</ws:updateServer>" );
|
||||
protected String createPayload(Server.Request.UpdatePayload payload) {
|
||||
requestBuilder.append("<ws:updateServer>")
|
||||
.append("<request>")
|
||||
.append(format("<serverId>%s</serverId>", payload.id()))
|
||||
.append(format("<cores>%s</cores>", payload.cores()))
|
||||
.append(format("<ram>%s</ram>", payload.ram()))
|
||||
.append(formatIfNotEmpty("<serverName>%s</serverName>", payload.name()))
|
||||
.append(formatIfNotEmpty("<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId()))
|
||||
.append(formatIfNotEmpty("<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId()))
|
||||
.append(formatIfNotEmpty("<osType>%s</osType>", payload.osType()))
|
||||
.append(formatIfNotEmpty("<availabilityZone>%s</availabilityZone>", payload.availabilityZone()))
|
||||
.append(formatIfNotEmpty("<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug()))
|
||||
.append(formatIfNotEmpty("<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug()))
|
||||
.append(formatIfNotEmpty("<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug()))
|
||||
.append(formatIfNotEmpty("<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug()))
|
||||
.append(formatIfNotEmpty("<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug()))
|
||||
.append(formatIfNotEmpty("<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug()))
|
||||
.append("</request>")
|
||||
.append("</ws:updateServer>");
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.storage;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
|
||||
public class ConnectStorageToServerRequestBinder extends BaseProfitBricksRequestBinder<Storage.Request.ConnectPayload> {
|
||||
|
||||
protected final StringBuilder requestBuilder;
|
||||
|
||||
ConnectStorageToServerRequestBinder() {
|
||||
super("storage");
|
||||
this.requestBuilder = new StringBuilder(128 * 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload(Storage.Request.ConnectPayload payload) {
|
||||
requestBuilder.append("<ws:connectStorageToServer>")
|
||||
.append("<request>")
|
||||
.append(format("<storageId>%s</storageId>", payload.storageId()))
|
||||
.append(format("<serverId>%s</serverId>", payload.serverId()))
|
||||
.append(formatIfNotEmpty("<busType>%s</busType>", payload.busType()))
|
||||
.append(formatIfNotEmpty("<deviceNumber>%s</deviceNumber>", payload.deviceNumber()))
|
||||
.append("</request>")
|
||||
.append("</ws:connectStorageToServer>");
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.storage;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
|
||||
public class CreateStorageRequestBinder extends BaseProfitBricksRequestBinder<Storage.Request.CreatePayload> {
|
||||
|
||||
protected final StringBuilder requestBuilder;
|
||||
|
||||
CreateStorageRequestBinder() {
|
||||
super("storage");
|
||||
this.requestBuilder = new StringBuilder(128 * 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload(Storage.Request.CreatePayload payload) {
|
||||
requestBuilder.append("<ws:createStorage>")
|
||||
.append("<request>")
|
||||
.append(format("<dataCenterId>%s</dataCenterId>", payload.dataCenterId()))
|
||||
.append(formatIfNotEmpty("<storageName>%s</storageName>", payload.name()))
|
||||
.append(format("<size>%.0f</size>", payload.size()))
|
||||
.append(formatIfNotEmpty("<mountImageId>%s</mountImageId>", payload.mountImageId()))
|
||||
.append(formatIfNotEmpty("<profitBricksImagePassword>%s</profitBricksImagePassword>", payload.profitBricksImagePassword()))
|
||||
.append("</request>")
|
||||
.append("</ws:createStorage>");
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.storage;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
|
||||
public class UpdateStorageRequestBinder extends BaseProfitBricksRequestBinder<Storage.Request.UpdatePayload> {
|
||||
|
||||
protected final StringBuilder requestBuilder;
|
||||
|
||||
UpdateStorageRequestBinder() {
|
||||
super("storage");
|
||||
this.requestBuilder = new StringBuilder(128 * 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload(Storage.Request.UpdatePayload payload) {
|
||||
requestBuilder
|
||||
.append("<ws:updateStorage>")
|
||||
.append("<request>")
|
||||
.append(format("<storageId>%s</storageId>", payload.id()))
|
||||
.append(formatIfNotEmpty("<size>%.0f</size>", payload.size()))
|
||||
.append(formatIfNotEmpty("<storageName>%s</storageName>", payload.name()))
|
||||
.append(formatIfNotEmpty("<mountImageId>%s</mountImageId>", payload.mountImageId()))
|
||||
.append("</request>")
|
||||
.append("</ws:updateStorage>");
|
||||
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -23,5 +23,5 @@ package org.jclouds.profitbricks.compute.internal;
|
|||
*/
|
||||
public enum ProvisioningStatusAware {
|
||||
|
||||
DATACENTER, SERVER;
|
||||
DATACENTER, SERVER, STORAGE;
|
||||
}
|
||||
|
|
|
@ -26,9 +26,8 @@ import com.google.common.base.Predicate;
|
|||
/**
|
||||
* A custom predicate for waiting until a virtual resource satisfies the given expected status
|
||||
* <p>
|
||||
* Performing api requests on a datacenter that is not {@link ProvisioningState#AVAILABLE} is not allowed. On some
|
||||
* cases, the API user gets blocked from further requests, and will then need to contact tech support for api lock
|
||||
* release.
|
||||
* Performing api requests on a datacenter that is not {@link ProvisioningState#AVAILABLE} is not allowed. On some cases, the API user gets
|
||||
* blocked from further requests, and will then need to contact tech support for api lock release.
|
||||
*/
|
||||
public class ProvisioningStatusPollingPredicate implements Predicate<String> {
|
||||
|
||||
|
@ -49,7 +48,9 @@ public class ProvisioningStatusPollingPredicate implements Predicate<String> {
|
|||
case DATACENTER:
|
||||
return expect == api.dataCenterApi().getDataCenterState(input);
|
||||
case SERVER:
|
||||
return expect == api.serverApi().getServer( input ).state();
|
||||
return expect == api.serverApi().getServer(input).state();
|
||||
case STORAGE:
|
||||
return expect == api.storageApi().getStorage(input).state();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown domain '" + domain + "'");
|
||||
}
|
||||
|
|
|
@ -55,14 +55,14 @@ public class ProfitBricksHttpApiModule extends HttpApiModule<ProfitBricksApi> {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new SSLModule());
|
||||
bind(HttpCommandExecutorService.class).to(ResponseStatusFromPayloadHttpCommandExecutorService.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
install(new SSLModule());
|
||||
bind(HttpCommandExecutorService.class).to(ResponseStatusFromPayloadHttpCommandExecutorService.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
public ParseSax<ServiceFault> serviceFaultParser(ParseSax.Factory factory, Injector injector) {
|
||||
return factory.create(injector.getInstance(ServiceFaultResponseHandler.class));
|
||||
return factory.create(injector.getInstance(ServiceFaultResponseHandler.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ public enum AvailabilityZone {
|
|||
return name();
|
||||
}
|
||||
|
||||
public static AvailabilityZone fromValue( String v ) {
|
||||
public static AvailabilityZone fromValue(String v) {
|
||||
try {
|
||||
return valueOf( v );
|
||||
} catch ( Exception ex ) {
|
||||
return valueOf(v);
|
||||
} catch (Exception ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,30 +19,43 @@ package org.jclouds.profitbricks.domain;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@AutoValue
|
||||
public abstract class DataCenter {
|
||||
|
||||
public abstract String id();
|
||||
|
||||
@Nullable public abstract String name();
|
||||
@Nullable
|
||||
public abstract String name();
|
||||
|
||||
public abstract int version();
|
||||
|
||||
@Nullable public abstract ProvisioningState state();
|
||||
@Nullable
|
||||
public abstract ProvisioningState state();
|
||||
|
||||
@Nullable public abstract Location location();
|
||||
@Nullable
|
||||
public abstract Location location();
|
||||
|
||||
// @Nullable public abstract List<Server> servers();
|
||||
// @Nullable public abstract List<Storage> storages();
|
||||
@Nullable
|
||||
public abstract List<Server> servers();
|
||||
|
||||
@Nullable
|
||||
public abstract List<Storage> storages();
|
||||
// @Nullable public abstract List<LoadBalancer> loadBalancers();
|
||||
public static DataCenter create(String id, String name, int version, ProvisioningState state, Location location) {
|
||||
return new AutoValue_DataCenter(id, name, version, state, location);
|
||||
|
||||
public static DataCenter create(String id, String name, int version, ProvisioningState state, Location location, List<Server> servers,
|
||||
List<Storage> storages) {
|
||||
return new AutoValue_DataCenter(id, name, version, state, location,
|
||||
servers != null ? ImmutableList.copyOf(servers) : Lists.<Server>newArrayList(),
|
||||
storages != null ? ImmutableList.copyOf(storages) : Lists.<Storage>newArrayList());
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
@ -60,76 +73,87 @@ public abstract class DataCenter {
|
|||
private ProvisioningState state;
|
||||
private Location location;
|
||||
private int version;
|
||||
// private List<Server> servers;
|
||||
// private List<Storage> storage;
|
||||
private List<Server> servers;
|
||||
private List<Storage> storages;
|
||||
// private List<LoadBalancer> loadBalancer;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(ProvisioningState state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder location(Location location) {
|
||||
this.location = location;
|
||||
return this;
|
||||
this.location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder version(int version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder servers(List<Server> servers) {
|
||||
this.servers = servers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder storages(List<Storage> storages) {
|
||||
this.storages = storages;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataCenter build() {
|
||||
return DataCenter.create(id, name, version, state, location);
|
||||
return DataCenter.create(id, name, version, state, location, servers, storages);
|
||||
}
|
||||
|
||||
public Builder fromDataCenter(DataCenter in) {
|
||||
return this.id(in.id()).name(in.name()).version(in.version()).state(in.state()).location(in.location());
|
||||
return this.id(in.id()).name(in.name()).version(in.version()).state(in.state()).location(in.location()).servers(in.servers())
|
||||
.storages(in.storages());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Request {
|
||||
|
||||
|
||||
@AutoValue
|
||||
public abstract static class CreatePayload {
|
||||
|
||||
public abstract String name();
|
||||
public abstract String name();
|
||||
|
||||
public abstract Location location();
|
||||
public abstract Location location();
|
||||
|
||||
public static CreatePayload create(String name, Location location) {
|
||||
public static CreatePayload create(String name, Location location) {
|
||||
checkInvalidChars(name);
|
||||
return new AutoValue_DataCenter_Request_CreatePayload(name, location);
|
||||
}
|
||||
return new AutoValue_DataCenter_Request_CreatePayload(name, location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class UpdatePayload {
|
||||
|
||||
public abstract String id();
|
||||
public abstract String id();
|
||||
|
||||
public abstract String name();
|
||||
public abstract String name();
|
||||
|
||||
public static UpdatePayload create(String id, String name) {
|
||||
public static UpdatePayload create(String id, String name) {
|
||||
checkInvalidChars(name);
|
||||
return new AutoValue_DataCenter_Request_UpdatePayload(id, name);
|
||||
}
|
||||
return new AutoValue_DataCenter_Request_UpdatePayload(id, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final Pattern INVALID_CHARS = Pattern.compile("^.*[@/\\|'`’^].*$");
|
||||
|
||||
private static void checkInvalidChars(String name){
|
||||
|
||||
private static void checkInvalidChars(String name) {
|
||||
checkArgument(!isNullOrEmpty(name), "Name is required.");
|
||||
checkArgument(!INVALID_CHARS.matcher(name).matches(), "Name must not contain any of: @ / \\ | ' ` ’ ^");
|
||||
}
|
||||
|
|
|
@ -35,16 +35,16 @@ public enum Location {
|
|||
|
||||
public static Location fromValue(String v) {
|
||||
try {
|
||||
return valueOf(v);
|
||||
return valueOf(v);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
public static Location fromId(String id) {
|
||||
for (Location location : values())
|
||||
if (location.id.equals(id))
|
||||
return location;
|
||||
if (location.id.equals(id))
|
||||
return location;
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ public enum ProvisioningState {
|
|||
|
||||
public static ProvisioningState fromValue(String value) {
|
||||
try {
|
||||
return valueOf(value);
|
||||
return valueOf(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,20 @@
|
|||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
import org.jclouds.profitbricks.domain.internal.ServerCommonProperties;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@AutoValue
|
||||
public abstract class Server implements ServerCommonProperties {
|
||||
|
||||
|
@ -34,10 +42,10 @@ public abstract class Server implements ServerCommonProperties {
|
|||
return name();
|
||||
}
|
||||
|
||||
public static Status fromValue( String v ) {
|
||||
public static Status fromValue(String v) {
|
||||
try {
|
||||
return valueOf( v );
|
||||
} catch ( IllegalArgumentException ex ) {
|
||||
return valueOf(v);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +78,17 @@ public abstract class Server implements ServerCommonProperties {
|
|||
@Nullable
|
||||
public abstract Date lastModificationTime();
|
||||
|
||||
// public abstract List<Storage> storages();
|
||||
// public abstract List<Nic> storages();
|
||||
public static Server create( String id, String name, int cores, int ram, Boolean hasInternetAccess, ProvisioningState state,
|
||||
Status status, OsType osType, AvailabilityZone availabilityZone, Date creationTime, Date lastModificationTime, Boolean isCpuHotPlug,
|
||||
Boolean isRamHotPlug, Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) {
|
||||
return new AutoValue_Server( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, isDiscVirtioHotUnPlug,
|
||||
cores, ram, id, name, hasInternetAccess, state, status, osType, availabilityZone, creationTime, lastModificationTime );
|
||||
@Nullable
|
||||
public abstract List<Storage> storages();
|
||||
|
||||
// public abstract List<Nic> nics();
|
||||
public static Server create(String id, String name, int cores, int ram, Boolean hasInternetAccess, ProvisioningState state,
|
||||
Status status, OsType osType, AvailabilityZone availabilityZone, Date creationTime, Date lastModificationTime,
|
||||
List<Storage> storages, Boolean isCpuHotPlug, Boolean isRamHotPlug, Boolean isNicHotPlug, Boolean isNicHotUnPlug,
|
||||
Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug) {
|
||||
return new AutoValue_Server(isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, isDiscVirtioHotUnPlug,
|
||||
cores, ram, id, name, hasInternetAccess, state, status, osType, availabilityZone, creationTime, lastModificationTime,
|
||||
storages != null ? ImmutableList.copyOf(storages) : Lists.<Storage>newArrayList());
|
||||
|
||||
}
|
||||
|
||||
|
@ -85,7 +97,7 @@ public abstract class Server implements ServerCommonProperties {
|
|||
}
|
||||
|
||||
public DescribingBuilder toBuilder() {
|
||||
return builder().fromServer( this );
|
||||
return builder().fromServer(this);
|
||||
}
|
||||
|
||||
public abstract static class Builder<B extends Builder, D extends ServerCommonProperties> {
|
||||
|
@ -100,48 +112,48 @@ public abstract class Server implements ServerCommonProperties {
|
|||
protected Boolean discVirtioHotPlug;
|
||||
protected Boolean discVirtioHotUnPlug;
|
||||
|
||||
public B name( String name ) {
|
||||
public B name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B cores( int cores ) {
|
||||
public B cores(int cores) {
|
||||
this.cores = cores;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B ram( int ram ) {
|
||||
public B ram(int ram) {
|
||||
this.ram = ram;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isCpuHotPlug( Boolean cpuHotPlug ) {
|
||||
public B isCpuHotPlug(Boolean cpuHotPlug) {
|
||||
this.cpuHotPlug = cpuHotPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isRamHotPlug( Boolean ramHotPlug ) {
|
||||
public B isRamHotPlug(Boolean ramHotPlug) {
|
||||
this.ramHotPlug = ramHotPlug;
|
||||
return self();
|
||||
|
||||
}
|
||||
|
||||
public B isNicHotPlug( Boolean nicHotPlug ) {
|
||||
public B isNicHotPlug(Boolean nicHotPlug) {
|
||||
this.nicHotPlug = nicHotPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isNicHotUnPlug( Boolean nicHotUnPlug ) {
|
||||
public B isNicHotUnPlug(Boolean nicHotUnPlug) {
|
||||
this.nicHotUnPlug = nicHotUnPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isDiscVirtioHotPlug( Boolean discVirtioHotPlug ) {
|
||||
public B isDiscVirtioHotPlug(Boolean discVirtioHotPlug) {
|
||||
this.discVirtioHotPlug = discVirtioHotPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isDiscVirtioHotUnPlug( Boolean discVirtioHotUnPlug ) {
|
||||
public B isDiscVirtioHotUnPlug(Boolean discVirtioHotUnPlug) {
|
||||
this.discVirtioHotUnPlug = discVirtioHotUnPlug;
|
||||
return self();
|
||||
}
|
||||
|
@ -161,59 +173,65 @@ public abstract class Server implements ServerCommonProperties {
|
|||
private Date creationTime;
|
||||
private Date lastModificationTime;
|
||||
private Boolean hasInternetAccess;
|
||||
private List<Storage> storages;
|
||||
|
||||
public DescribingBuilder id( String id ) {
|
||||
public DescribingBuilder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder state( ProvisioningState state ) {
|
||||
public DescribingBuilder state(ProvisioningState state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder status( Status status ) {
|
||||
public DescribingBuilder status(Status status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder osType( OsType osType ) {
|
||||
public DescribingBuilder osType(OsType osType) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder availabilityZone( AvailabilityZone zone ) {
|
||||
public DescribingBuilder availabilityZone(AvailabilityZone zone) {
|
||||
this.zone = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder creationTime( Date creationTime ) {
|
||||
public DescribingBuilder creationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder lastModificationTime( Date lastModificationTime ) {
|
||||
public DescribingBuilder lastModificationTime(Date lastModificationTime) {
|
||||
this.lastModificationTime = lastModificationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder hasInternetAccess( Boolean hasInternetAccess ) {
|
||||
public DescribingBuilder hasInternetAccess(Boolean hasInternetAccess) {
|
||||
this.hasInternetAccess = hasInternetAccess;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder storages(List<Storage> storages) {
|
||||
this.storages = storages;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server build() {
|
||||
return Server.create( id, name, cores, ram, hasInternetAccess, state, status, osType, zone, creationTime,
|
||||
lastModificationTime, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug );
|
||||
return Server.create(id, name, cores, ram, hasInternetAccess, state, status, osType, zone, creationTime,
|
||||
lastModificationTime, storages, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug);
|
||||
}
|
||||
|
||||
private DescribingBuilder fromServer( Server in ) {
|
||||
return this.id( in.id() ).cores( in.cores() ).creationTime( in.creationTime() ).hasInternetAccess( in.hasInternetAccess() )
|
||||
.isCpuHotPlug( in.isCpuHotPlug() ).isDiscVirtioHotPlug( in.isDiscVirtioHotPlug() ).isDiscVirtioHotUnPlug( in.isDiscVirtioHotUnPlug() )
|
||||
.isNicHotPlug( in.isNicHotPlug() ).isNicHotUnPlug( in.isNicHotUnPlug() ).isRamHotPlug( in.isRamHotPlug() )
|
||||
.lastModificationTime( in.lastModificationTime() ).name( in.name() ).osType( in.osType() ).ram( in.ram() ).state( in.state() )
|
||||
.status( in.status() );
|
||||
private DescribingBuilder fromServer(Server in) {
|
||||
return this.id(in.id()).cores(in.cores()).creationTime(in.creationTime()).hasInternetAccess(in.hasInternetAccess())
|
||||
.isCpuHotPlug(in.isCpuHotPlug()).isDiscVirtioHotPlug(in.isDiscVirtioHotPlug()).isDiscVirtioHotUnPlug(in.isDiscVirtioHotUnPlug())
|
||||
.isNicHotPlug(in.isNicHotPlug()).isNicHotUnPlug(in.isNicHotUnPlug()).isRamHotPlug(in.isRamHotPlug())
|
||||
.lastModificationTime(in.lastModificationTime()).name(in.name()).osType(in.osType()).ram(in.ram()).state(in.state())
|
||||
.status(in.status()).storages(in.storages());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -256,18 +274,18 @@ public abstract class Server implements ServerCommonProperties {
|
|||
@Nullable
|
||||
public abstract OsType osType();
|
||||
|
||||
public static CreatePayload create( String dataCenterId, String name, int core, int ram ) {
|
||||
return create( dataCenterId, name, core, ram, "", "", null, false, null, null, null, null, null, null, null, null );
|
||||
public static CreatePayload create(String dataCenterId, String name, int core, int ram) {
|
||||
return create(dataCenterId, name, core, ram, "", "", null, false, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static CreatePayload create( String dataCenterId, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId,
|
||||
public static CreatePayload create(String dataCenterId, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId,
|
||||
Integer lanId, Boolean hasInternetAccess, AvailabilityZone availabilityZone, OsType osType, Boolean isCpuHotPlug, Boolean isRamHotPlug,
|
||||
Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) {
|
||||
validateCores( cores );
|
||||
validateRam( ram, isRamHotPlug );
|
||||
return new AutoValue_Server_Request_CreatePayload( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug,
|
||||
Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug) {
|
||||
validateCores(cores);
|
||||
validateRam(ram, isRamHotPlug);
|
||||
return new AutoValue_Server_Request_CreatePayload(isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug,
|
||||
isDiscVirtioHotUnPlug, name, cores, ram, dataCenterId, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess,
|
||||
availabilityZone, osType );
|
||||
availabilityZone, osType);
|
||||
}
|
||||
|
||||
public static class Builder extends Server.Builder<Builder, CreatePayload> {
|
||||
|
@ -280,42 +298,42 @@ public abstract class Server implements ServerCommonProperties {
|
|||
private AvailabilityZone availabilityZone;
|
||||
private OsType osType;
|
||||
|
||||
public Builder dataCenterId( String dataCenterId ) {
|
||||
public Builder dataCenterId(String dataCenterId) {
|
||||
this.dataCenterId = dataCenterId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dataCenterId( DataCenter dataCenter ) {
|
||||
this.dataCenterId = checkNotNull( dataCenter, "Cannot pass null datacenter" ).id();
|
||||
public Builder dataCenterId(DataCenter dataCenter) {
|
||||
this.dataCenterId = checkNotNull(dataCenter, "Cannot pass null datacenter").id();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromStorageId( String storageId ) {
|
||||
public Builder bootFromStorageId(String storageId) {
|
||||
this.bootFromStorageId = storageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromImageId( String image ) {
|
||||
public Builder bootFromImageId(String image) {
|
||||
this.bootFromImageId = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lanId( Integer lanId ) {
|
||||
public Builder lanId(Integer lanId) {
|
||||
this.lanId = lanId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder availabilityZone( AvailabilityZone zone ) {
|
||||
public Builder availabilityZone(AvailabilityZone zone) {
|
||||
this.availabilityZone = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder osType( OsType osType ) {
|
||||
public Builder osType(OsType osType) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasInternetAccess( Boolean hasInternetAccess ) {
|
||||
public Builder hasInternetAccess(Boolean hasInternetAccess) {
|
||||
this.hasInternetAccess = hasInternetAccess;
|
||||
return this;
|
||||
}
|
||||
|
@ -327,8 +345,8 @@ public abstract class Server implements ServerCommonProperties {
|
|||
|
||||
@Override
|
||||
public CreatePayload build() {
|
||||
return CreatePayload.create( dataCenterId, name, cores, ram, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess,
|
||||
availabilityZone, osType, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug );
|
||||
return CreatePayload.create(dataCenterId, name, cores, ram, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess,
|
||||
availabilityZone, osType, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -355,11 +373,11 @@ public abstract class Server implements ServerCommonProperties {
|
|||
@Nullable
|
||||
public abstract OsType osType();
|
||||
|
||||
public static UpdatePayload create( String id, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId,
|
||||
public static UpdatePayload create(String id, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId,
|
||||
AvailabilityZone availabilityZone, OsType osType, Boolean isCpuHotPlug, Boolean isRamHotPlug, Boolean isNicHotPlug,
|
||||
Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) {
|
||||
return new AutoValue_Server_Request_UpdatePayload( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug,
|
||||
isDiscVirtioHotUnPlug, cores, ram, name, id, bootFromStorageId, bootFromImageId, availabilityZone, osType );
|
||||
Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug) {
|
||||
return new AutoValue_Server_Request_UpdatePayload(isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug,
|
||||
isDiscVirtioHotUnPlug, cores, ram, name, id, bootFromStorageId, bootFromImageId, availabilityZone, osType);
|
||||
}
|
||||
|
||||
public static class Builder extends Server.Builder<Builder, UpdatePayload> {
|
||||
|
@ -370,27 +388,27 @@ public abstract class Server implements ServerCommonProperties {
|
|||
private AvailabilityZone availabilityZone;
|
||||
private OsType osType;
|
||||
|
||||
public Builder id( String id ) {
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromStorageId( String storageId ) {
|
||||
public Builder bootFromStorageId(String storageId) {
|
||||
this.bootFromStorageId = storageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromImageId( String image ) {
|
||||
public Builder bootFromImageId(String image) {
|
||||
this.bootFromImageId = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder availabilityZone( AvailabilityZone zone ) {
|
||||
public Builder availabilityZone(AvailabilityZone zone) {
|
||||
this.availabilityZone = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder osType( OsType osType ) {
|
||||
public Builder osType(OsType osType) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
@ -402,8 +420,8 @@ public abstract class Server implements ServerCommonProperties {
|
|||
|
||||
@Override
|
||||
public UpdatePayload build() {
|
||||
return UpdatePayload.create( id, name, cores, ram, bootFromStorageId, bootFromImageId, availabilityZone, osType,
|
||||
cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug );
|
||||
return UpdatePayload.create(id, name, cores, ram, bootFromStorageId, bootFromImageId, availabilityZone, osType,
|
||||
cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug);
|
||||
|
||||
}
|
||||
|
||||
|
@ -412,13 +430,13 @@ public abstract class Server implements ServerCommonProperties {
|
|||
|
||||
}
|
||||
|
||||
private static void validateCores( int cores ) {
|
||||
checkArgument( cores > 0, "Core must be atleast 1." );
|
||||
private static void validateCores(int cores) {
|
||||
checkArgument(cores > 0, "Core must be atleast 1.");
|
||||
}
|
||||
|
||||
private static void validateRam( int ram, Boolean isRamHotPlug ) {
|
||||
int minRam = ( isRamHotPlug == null || !isRamHotPlug ) ? 256 : 1024;
|
||||
checkArgument( ram >= minRam && ram % 256 == 0, "RAM must be multiples of 256 with minimum of 256 MB (1024 MB if ramHotPlug is enabled)" );
|
||||
private static void validateRam(int ram, Boolean isRamHotPlug) {
|
||||
int minRam = (isRamHotPlug == null || !isRamHotPlug) ? 256 : 1024;
|
||||
checkArgument(ram >= minRam && ram % 256 == 0, "RAM must be multiples of 256 with minimum of 256 MB (1024 MB if ramHotPlug is enabled)");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,11 +36,11 @@ public abstract class ServiceFault {
|
|||
UNRECOGNIZED;
|
||||
|
||||
public static FaultCode fromValue(String v) {
|
||||
try {
|
||||
return valueOf(v);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
try {
|
||||
return valueOf(v);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,27 +68,27 @@ public abstract class ServiceFault {
|
|||
private int requestId;
|
||||
|
||||
public Builder faultCode(FaultCode code) {
|
||||
this.faultCode = code;
|
||||
return this;
|
||||
this.faultCode = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder httpCode(int httpCode) {
|
||||
this.httpCode = httpCode;
|
||||
return this;
|
||||
this.httpCode = httpCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder message(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder requestId(int requestId) {
|
||||
this.requestId = requestId;
|
||||
return this;
|
||||
this.requestId = requestId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServiceFault build() {
|
||||
return create(faultCode, httpCode, message, requestId);
|
||||
return create(faultCode, httpCode, message, requestId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@AutoValue
|
||||
public abstract class Storage {
|
||||
|
||||
public enum BusType {
|
||||
|
||||
IDE, SCSI, VIRTIO, UNRECOGNIZED;
|
||||
|
||||
public static BusType fromValue(String value) {
|
||||
try {
|
||||
return valueOf(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String id();
|
||||
|
||||
@Nullable
|
||||
public abstract String name();
|
||||
|
||||
public abstract float size(); // GB
|
||||
|
||||
@Nullable
|
||||
public abstract Date creationTime();
|
||||
|
||||
@Nullable
|
||||
public abstract Date lastModificationTime();
|
||||
|
||||
public abstract ProvisioningState state();
|
||||
|
||||
@Nullable
|
||||
public abstract List<String> serverIds();
|
||||
|
||||
@Nullable
|
||||
public abstract Boolean bootDevice();
|
||||
|
||||
@Nullable
|
||||
public abstract BusType busType();
|
||||
|
||||
@Nullable
|
||||
public abstract Integer deviceNumber();
|
||||
|
||||
public static Storage create(String id, String name, float size, Date creationTime, Date lastModificationTime,
|
||||
ProvisioningState state, List<String> serverIds, Boolean bootDevice, BusType busType, Integer deviceNumber) {
|
||||
return new AutoValue_Storage(id, name, size, creationTime, lastModificationTime, state,
|
||||
serverIds != null ? ImmutableList.copyOf(serverIds) : Lists.<String>newArrayList(),
|
||||
bootDevice, busType, deviceNumber);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromStorage(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private float size;
|
||||
private Date creationTime;
|
||||
private Date lastModificationTime;
|
||||
private ProvisioningState state;
|
||||
private List<String> serverIds;
|
||||
private Boolean bootDevice;
|
||||
private BusType busType;
|
||||
private Integer deviceNumber;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(float size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder creationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lastModificationTime(Date lastModificationTime) {
|
||||
this.lastModificationTime = lastModificationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(ProvisioningState state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder serverIds(List<String> serverIds) {
|
||||
this.serverIds = serverIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootDevice(Boolean bootDevice) {
|
||||
this.bootDevice = bootDevice;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder busType(BusType busType) {
|
||||
this.busType = busType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder deviceNumber(Integer deviceNumber) {
|
||||
this.deviceNumber = deviceNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Builder fromStorage(Storage in) {
|
||||
return this.id(in.id()).name(in.name()).size(in.size()).creationTime(in.creationTime())
|
||||
.lastModificationTime(in.lastModificationTime()).state(in.state()).serverIds(in.serverIds())
|
||||
.bootDevice(in.bootDevice()).busType(in.busType()).deviceNumber(in.deviceNumber());
|
||||
}
|
||||
|
||||
public Storage build() {
|
||||
return Storage.create(id, name, size, creationTime, lastModificationTime, state, serverIds, bootDevice, busType, deviceNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class Request {
|
||||
|
||||
public static CreatePayload.Builder creatingBuilder() {
|
||||
return new CreatePayload.Builder();
|
||||
}
|
||||
|
||||
public static UpdatePayload.Builder updatingBuilder() {
|
||||
return new UpdatePayload.Builder();
|
||||
}
|
||||
|
||||
public static ConnectPayload.Builder connectingBuilder() {
|
||||
return new ConnectPayload.Builder();
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class CreatePayload {
|
||||
|
||||
public abstract String dataCenterId();
|
||||
|
||||
public abstract float size();
|
||||
|
||||
@Nullable
|
||||
public abstract String name();
|
||||
|
||||
@Nullable
|
||||
public abstract String mountImageId();
|
||||
|
||||
@Nullable
|
||||
public abstract String profitBricksImagePassword();
|
||||
|
||||
public static CreatePayload create(String dataCenterId, float size, String name, String mountImageId, String imagePassword) {
|
||||
validateSize(size);
|
||||
return new AutoValue_Storage_Request_CreatePayload(dataCenterId, size, name, mountImageId, imagePassword);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String dataCenterId;
|
||||
private float size;
|
||||
private String name;
|
||||
private String mountImageId;
|
||||
private String profitBricksImagePassword;
|
||||
|
||||
public Builder dataCenterId(String dataCenterId) {
|
||||
this.dataCenterId = dataCenterId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dataCenterId(DataCenter dataCenter) {
|
||||
this.dataCenterId = checkNotNull(dataCenter, "Cannot pass null datacenter").id();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(float size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mountImageId(String mountImageId) {
|
||||
this.mountImageId = mountImageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder imagePassword(String password) {
|
||||
this.profitBricksImagePassword = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreatePayload build() {
|
||||
return CreatePayload.create(dataCenterId, size, name, mountImageId, profitBricksImagePassword);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class UpdatePayload {
|
||||
|
||||
public abstract String id();
|
||||
|
||||
@Nullable
|
||||
public abstract Float size();
|
||||
|
||||
@Nullable
|
||||
public abstract String name();
|
||||
|
||||
@Nullable
|
||||
public abstract String mountImageId();
|
||||
|
||||
public static UpdatePayload create(String id, Float size, String name, String mountImageId) {
|
||||
validateSize(size);
|
||||
return new AutoValue_Storage_Request_UpdatePayload(id, size, name, mountImageId);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String id;
|
||||
private Float size;
|
||||
private String name;
|
||||
private String mountImageId;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(float size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mountImageId(String mountImageId) {
|
||||
this.mountImageId = mountImageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdatePayload build() {
|
||||
return UpdatePayload.create(id, size, name, mountImageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class ConnectPayload {
|
||||
|
||||
public abstract String storageId();
|
||||
|
||||
public abstract String serverId();
|
||||
|
||||
@Nullable
|
||||
public abstract BusType busType();
|
||||
|
||||
@Nullable
|
||||
public abstract Integer deviceNumber();
|
||||
|
||||
public static ConnectPayload create(String storageId, String serverId, BusType busType, Integer deviceNumber) {
|
||||
return new AutoValue_Storage_Request_ConnectPayload(storageId, serverId, busType, deviceNumber);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String storageId;
|
||||
private String serverId;
|
||||
private BusType busType;
|
||||
private Integer deviceNumber;
|
||||
|
||||
public Builder storageId(String storageId) {
|
||||
this.storageId = storageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder serverId(String serverId) {
|
||||
this.serverId = serverId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder busType(BusType busType) {
|
||||
this.busType = busType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder deviceNumber(Integer deviceNumber) {
|
||||
this.deviceNumber = deviceNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConnectPayload build() {
|
||||
return ConnectPayload.create(storageId, serverId, busType, deviceNumber);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateSize(Float size) {
|
||||
if (size != null)
|
||||
checkArgument(size > 1, "Storage size must be > 1GB");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -58,8 +58,7 @@ public interface DataCenterApi {
|
|||
|
||||
/**
|
||||
* @param identifier Data Center identifier
|
||||
* @return Returns information about an existing virtual data center's state and configuration or <code>null</code>
|
||||
* if it doesn't exist.
|
||||
* @return Returns information about an existing virtual data center's state and configuration or <code>null</code> if it doesn't exist.
|
||||
*/
|
||||
@POST
|
||||
@Named("datacenter:get")
|
||||
|
@ -69,8 +68,8 @@ public interface DataCenterApi {
|
|||
DataCenter getDataCenter(@PayloadParam("id") String identifier);
|
||||
|
||||
/**
|
||||
* This is a lightweight function for polling the current provisioning state of the Virtual Data Center. It is
|
||||
* recommended to use this function for large Virtual Data Centers to query request results.
|
||||
* This is a lightweight function for polling the current provisioning state of the Virtual Data Center. It is recommended to use this
|
||||
* function for large Virtual Data Centers to query request results.
|
||||
* <p>
|
||||
* @param identifier Data Center identifier
|
||||
*/
|
||||
|
@ -119,9 +118,8 @@ public interface DataCenterApi {
|
|||
DataCenter clearDataCenter(@PayloadParam("id") String identifier);
|
||||
|
||||
/**
|
||||
* Deletes an Virtual Data Center. If a previous request on the target data center is still in progress, the data
|
||||
* center is going to be deleted after this request has been completed. Once a Data Center has been deleted, no
|
||||
* further request can be performed on it.
|
||||
* Deletes an Virtual Data Center. If a previous request on the target data center is still in progress, the data center is going to be
|
||||
* deleted after this request has been completed. Once a Data Center has been deleted, no further request can be performed on it.
|
||||
* <p>
|
||||
* @param identifier Identifier of the virtual data center
|
||||
* @return Returns a boolean indicating whether delete operation was made
|
||||
|
|
|
@ -39,19 +39,19 @@ import org.jclouds.rest.annotations.PayloadParam;
|
|||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
||||
@RequestFilters( { BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class } )
|
||||
@Consumes( MediaType.TEXT_XML )
|
||||
@Produces( MediaType.TEXT_XML )
|
||||
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||
@Consumes(MediaType.TEXT_XML)
|
||||
@Produces(MediaType.TEXT_XML)
|
||||
public interface ServerApi {
|
||||
|
||||
/**
|
||||
* @return Returns information about all virtual server, such as configuration, provisioning status, power status, etc.
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:getall" )
|
||||
@Payload( "<ws:getAllServers/>" )
|
||||
@XMLResponseParser( ServerListResponseHandler.class )
|
||||
@Fallback( Fallbacks.EmptyListOnNotFoundOr404.class )
|
||||
@Named("server:getall")
|
||||
@Payload("<ws:getAllServers/>")
|
||||
@XMLResponseParser(ServerListResponseHandler.class)
|
||||
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||
List<Server> getAllServers();
|
||||
|
||||
/**
|
||||
|
@ -59,11 +59,11 @@ public interface ServerApi {
|
|||
* @return Returns information about a virtual server, such as configuration, provisioning status, power status, etc.
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:get" )
|
||||
@Payload( "<ws:getServer><serverId>{id}</serverId></ws:getServer>" )
|
||||
@XMLResponseParser( ServerInfoResponseHandler.class )
|
||||
@Fallback( Fallbacks.NullOnNotFoundOr404.class )
|
||||
Server getServer( @PayloadParam( "id" ) String identifier );
|
||||
@Named("server:get")
|
||||
@Payload("<ws:getServer><serverId>{id}</serverId></ws:getServer>")
|
||||
@XMLResponseParser(ServerInfoResponseHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Server getServer(@PayloadParam("id") String identifier);
|
||||
|
||||
/**
|
||||
* Starts an existing virtual server
|
||||
|
@ -77,10 +77,10 @@ public interface ServerApi {
|
|||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:start" )
|
||||
@Payload( "<ws:startServer><serverId>{id}</serverId></ws:startServer>" )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String startServer( @PayloadParam( "id" ) String id );
|
||||
@Named("server:start")
|
||||
@Payload("<ws:startServer><serverId>{id}</serverId></ws:startServer>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String startServer(@PayloadParam("id") String id);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -99,10 +99,10 @@ public interface ServerApi {
|
|||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:stop" )
|
||||
@Payload( "<ws:stopServer><serverId>{id}</serverId></ws:stopServer>" )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String stopServer( @PayloadParam( "id" ) String id );
|
||||
@Named("server:stop")
|
||||
@Payload("<ws:stopServer><serverId>{id}</serverId></ws:stopServer>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String stopServer(@PayloadParam("id") String id);
|
||||
|
||||
/**
|
||||
* Resets an existing virtual server (POWER CYCLE).
|
||||
|
@ -119,10 +119,10 @@ public interface ServerApi {
|
|||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:reset" )
|
||||
@Payload( "<ws:resetServer><serverId>{id}</serverId></ws:resetServer>" )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String resetServer( @PayloadParam( "id" ) String id );
|
||||
@Named("server:reset")
|
||||
@Payload("<ws:resetServer><serverId>{id}</serverId></ws:resetServer>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String resetServer(@PayloadParam("id") String id);
|
||||
|
||||
/**
|
||||
* Creates a Virtual Server within an existing data center. Parameters can be specified to set up a boot device and connect the server to
|
||||
|
@ -132,22 +132,22 @@ public interface ServerApi {
|
|||
* @return serverId of the created server
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:create" )
|
||||
@MapBinder( CreateServerRequestBinder.class )
|
||||
@XMLResponseParser( ServerIdOnlyResponseHandler.class )
|
||||
String createServer( @PayloadParam( "server" ) Server.Request.CreatePayload payload );
|
||||
@Named("server:create")
|
||||
@MapBinder(CreateServerRequestBinder.class)
|
||||
@XMLResponseParser(ServerIdOnlyResponseHandler.class)
|
||||
String createServer(@PayloadParam("server") Server.Request.CreatePayload payload);
|
||||
|
||||
/**
|
||||
* Updates parameters of an existing virtual server device.
|
||||
*
|
||||
* @param payload Paylaod
|
||||
* @param payload Payload
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:update" )
|
||||
@MapBinder( UpdateServerRequestBinder.class )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String updateServer( @PayloadParam( "server" ) Server.Request.UpdatePayload payload );
|
||||
@Named("server:update")
|
||||
@MapBinder(UpdateServerRequestBinder.class)
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String updateServer(@PayloadParam("server") Server.Request.UpdatePayload payload);
|
||||
|
||||
/**
|
||||
* Deletes an existing Virtual Server.
|
||||
|
@ -156,9 +156,9 @@ public interface ServerApi {
|
|||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:delete" )
|
||||
@Payload( "<ws:deleteServer><serverId>{id}</serverId></ws:deleteServer>" )
|
||||
@Fallback( Fallbacks.FalseOnNotFoundOr404.class )
|
||||
boolean deleteServer( @PayloadParam( "id" ) String id );
|
||||
@Named("server:delete")
|
||||
@Payload("<ws:deleteServer><serverId>{id}</serverId></ws:deleteServer>")
|
||||
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||
boolean deleteServer(@PayloadParam("id") String id);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.Fallbacks;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.profitbricks.binder.storage.ConnectStorageToServerRequestBinder;
|
||||
import org.jclouds.profitbricks.binder.storage.CreateStorageRequestBinder;
|
||||
import org.jclouds.profitbricks.binder.storage.UpdateStorageRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.storage.StorageIdOnlyResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.storage.StorageInfoResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.Payload;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
||||
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||
@Consumes(MediaType.TEXT_XML)
|
||||
@Produces(MediaType.TEXT_XML)
|
||||
public interface StorageApi {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns information about all virtual storage, such as configuration and provisioning state.
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:getall")
|
||||
@Payload("<ws:getAllStorages/>")
|
||||
@XMLResponseParser(StorageListResponseHandler.class)
|
||||
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||
List<Storage> getAllStorages();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id Storage identifier
|
||||
* @return Returns information about a virtual storage’s configuration and provisioning state.
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:get")
|
||||
@Payload("<ws:getStorage><storageId>{id}</storageId></ws:getStorage>")
|
||||
@XMLResponseParser(StorageInfoResponseHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Storage getStorage(@PayloadParam("id") String id);
|
||||
|
||||
/**
|
||||
* Creates a virtual storage within an existing virtual data center. Additional parameters can be specified, e.g. for assigning a HDD
|
||||
* image to the storage.
|
||||
*
|
||||
* @param payload Payload
|
||||
* @return storageId of the created storage
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:create")
|
||||
@MapBinder(CreateStorageRequestBinder.class)
|
||||
@XMLResponseParser(StorageIdOnlyResponseHandler.class)
|
||||
String createStorage(@PayloadParam("storage") Storage.Request.CreatePayload payload);
|
||||
|
||||
/**
|
||||
* Updates parameters of an existing virtual storage device. It is possible to increase the storage size without reboot of an already
|
||||
* provisioned storage. The additional capacity is not added to any partition. You have to partition the storage afterwards. Vice versa,
|
||||
* it is not possible to decrease the storage size of an already provisioned storage.
|
||||
*
|
||||
* @param payload Payload
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:update")
|
||||
@MapBinder(UpdateStorageRequestBinder.class)
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String updateStorage(@PayloadParam("storage") Storage.Request.UpdatePayload payload);
|
||||
|
||||
/**
|
||||
* Deletes an existing virtual storage device.
|
||||
*
|
||||
* @param id Identifier of the target virtual storage
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:delete")
|
||||
@Payload("<ws:deleteStorage><storageId>{id}</storageId></ws:deleteStorage>")
|
||||
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||
boolean deleteStorage(@PayloadParam("id") String id);
|
||||
|
||||
/**
|
||||
* Connects a virtual storage device to an existing server.
|
||||
*
|
||||
* @param payload Payload
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:connect")
|
||||
@MapBinder(ConnectStorageToServerRequestBinder.class)
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String connectStorageToServer(@PayloadParam("storage") Storage.Request.ConnectPayload payload);
|
||||
|
||||
/**
|
||||
* Disconnects a virtual storage device from a connected server.
|
||||
*
|
||||
* @param storageId Identifier of the connected virtual storage
|
||||
* @param serverId Identifier of the connected virtual server
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named("storage:disconnect")
|
||||
@Payload("<ws:disconnectStorageFromServer><storageId>{storageId}</storageId><serverId>{serverId}</serverId></ws:disconnectStorageFromServer>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String disconnectStorageFromServer(@PayloadParam("storageId") String storageId, @PayloadParam("serverId") String serverId);
|
||||
}
|
|
@ -23,6 +23,7 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
@ -40,31 +41,35 @@ public class ProfitBricksHttpErrorHandler implements HttpErrorHandler {
|
|||
public void handleError(final HttpCommand command, final HttpResponse response) {
|
||||
Exception exception = null;
|
||||
try {
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
case 405:
|
||||
exception = new IllegalArgumentException(response.getMessage(), exception);
|
||||
break;
|
||||
case 401:
|
||||
exception = new AuthorizationException(response.getMessage(), exception);
|
||||
break;
|
||||
case 402:
|
||||
case 409:
|
||||
exception = new IllegalStateException(response.getMessage(), exception);
|
||||
break;
|
||||
case 404:
|
||||
case 410:
|
||||
if (!command.getCurrentRequest().getMethod().equals("DELETE"))
|
||||
exception = new ResourceNotFoundException(response.getMessage(), exception);
|
||||
break;
|
||||
case 413:
|
||||
case 503:
|
||||
exception = new InsufficientResourcesException(response.getMessage(), exception);
|
||||
break;
|
||||
}
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
case 405:
|
||||
exception = new IllegalArgumentException(response.getMessage(), exception);
|
||||
break;
|
||||
case 401:
|
||||
exception = new AuthorizationException("This request requires authentication.", exception);
|
||||
break;
|
||||
case 402:
|
||||
case 409:
|
||||
exception = new IllegalStateException(response.getMessage(), exception);
|
||||
break;
|
||||
case 404:
|
||||
case 410:
|
||||
if (!command.getCurrentRequest().getMethod().equals("DELETE"))
|
||||
exception = new ResourceNotFoundException(response.getMessage(), exception);
|
||||
break;
|
||||
case 413:
|
||||
case 503:
|
||||
// if nothing (default message was OK) was parsed from command executor, assume it was an 503 (Maintenance) html response.
|
||||
if (response.getMessage().equals("OK"))
|
||||
exception = new HttpResponseException("The ProfitBricks team is currently carrying out maintenance.", command, response);
|
||||
else
|
||||
exception = new InsufficientResourcesException(response.getMessage(), exception);
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
closeQuietly(response.getPayload());
|
||||
command.setException(exception);
|
||||
closeQuietly(response.getPayload());
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -51,20 +52,22 @@ import com.google.inject.Inject;
|
|||
/**
|
||||
* Custom implementation of the HTTP driver to read actual http status and message from SOAP Fault.
|
||||
* <br/>
|
||||
* ProfitBricks API errors are always returned with 500 HTTP code. This class parses and reads the SOAP response to map the actual http code
|
||||
* and message
|
||||
* ProfitBricks API errors are always returned with 500 HTTP code. This class parses and reads the SOAP response to map
|
||||
* the actual http code and message
|
||||
*/
|
||||
@Singleton
|
||||
public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrlHttpCommandExecutorService {
|
||||
|
||||
private final ParseSax<ServiceFault> faultHandler;
|
||||
|
||||
private static final Pattern endSoapTag = Pattern.compile("</.+:Envelope>$");
|
||||
|
||||
@Inject
|
||||
ResponseStatusFromPayloadHttpCommandExecutorService(HttpUtils utils, ContentMetadataCodec contentMetadataCodec,
|
||||
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
||||
DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier,
|
||||
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider, Function<URI, Proxy> proxyForURI,
|
||||
ParseSax<ServiceFault> faultHandler) {
|
||||
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
||||
DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier,
|
||||
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider, Function<URI, Proxy> proxyForURI,
|
||||
ParseSax<ServiceFault> faultHandler) {
|
||||
super(utils, contentMetadataCodec, retryHandler, ioRetryHandler, errorHandler, wire, verifier, untrustedSSLContextProvider, proxyForURI);
|
||||
this.faultHandler = faultHandler;
|
||||
}
|
||||
|
@ -74,38 +77,40 @@ public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrl
|
|||
HttpResponse originalResponse = super.invoke(connection);
|
||||
HttpResponse.Builder<?> responseBuilder = originalResponse.toBuilder();
|
||||
|
||||
if (hasPayload(originalResponse) && hasServerError(originalResponse)) {
|
||||
// As we need to read the response body to determine if there are errors, but we may need to process the body
|
||||
// again later in the response parsers if everything is OK, we buffer the body into an InputStream we can reset
|
||||
InputStream in = null;
|
||||
InputStream originalInputStream = originalResponse.getPayload().openStream();
|
||||
if (originalInputStream instanceof ByteArrayInputStream)
|
||||
in = originalInputStream;
|
||||
else
|
||||
try {
|
||||
in = new ByteArrayInputStream(ByteStreams.toByteArray(originalInputStream));
|
||||
} finally {
|
||||
closeQuietly(originalInputStream);
|
||||
}
|
||||
if (hasServerError(originalResponse) && hasPayload(originalResponse)) {
|
||||
// As we need to read the response body to determine if there are errors, but we may need to process the body
|
||||
// again later in the response parsers if everything is OK, we buffer the body into an InputStream we can reset
|
||||
InputStream in = null;
|
||||
InputStream originalInputStream = originalResponse.getPayload().openStream();
|
||||
|
||||
try {
|
||||
ServiceFault fault = faultHandler.parse(in);
|
||||
if (fault != null)
|
||||
responseBuilder
|
||||
.statusCode(fault.httpCode())
|
||||
.message(fault.message());
|
||||
} catch (Exception ex) {
|
||||
// ignore
|
||||
} finally {
|
||||
// Reset the input stream and set the payload, so it can be read again
|
||||
// by the response and error parsers
|
||||
if (in != null) {
|
||||
in.reset();
|
||||
Payload payload = Payloads.newInputStreamPayload(in);
|
||||
contentMetadataCodec.fromHeaders(payload.getContentMetadata(), originalResponse.getHeaders());
|
||||
responseBuilder.payload(payload);
|
||||
}
|
||||
}
|
||||
if (originalInputStream instanceof ByteArrayInputStream)
|
||||
in = originalInputStream;
|
||||
else
|
||||
try {
|
||||
in = new ByteArrayInputStream(ByteStreams.toByteArray(originalInputStream));
|
||||
} finally {
|
||||
closeQuietly(originalInputStream);
|
||||
}
|
||||
try {
|
||||
if (isSoapPayload(in)) {
|
||||
ServiceFault fault = faultHandler.parse(in);
|
||||
if (fault != null)
|
||||
responseBuilder
|
||||
.statusCode(fault.httpCode())
|
||||
.message(fault.message());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// ignore
|
||||
} finally {
|
||||
// Reset the input stream and set the payload, so it can be read again
|
||||
// by the response and error parsers
|
||||
if (in != null) {
|
||||
in.reset();
|
||||
Payload payload = Payloads.newInputStreamPayload(in);
|
||||
contentMetadataCodec.fromHeaders(payload.getContentMetadata(), originalResponse.getHeaders());
|
||||
responseBuilder.payload(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return responseBuilder.build();
|
||||
|
@ -119,4 +124,17 @@ public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrl
|
|||
return response.getPayload() != null && response.getPayload().getRawContent() != null;
|
||||
}
|
||||
|
||||
private static boolean isSoapPayload(final InputStream is) throws IOException {
|
||||
int size = is.available();
|
||||
char[] chars = new char[size];
|
||||
byte[] bytes = new byte[size];
|
||||
|
||||
is.read(bytes, 0, size);
|
||||
for (int i = 0; i < size;)
|
||||
chars[i] = (char) (bytes[i++] & 0xff);
|
||||
|
||||
is.reset(); // throws premature end of file w/o this
|
||||
|
||||
return endSoapTag.matcher(new String(chars)).find();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ import org.jclouds.io.Payloads;
|
|||
public class ProfitBricksSoapMessageEnvelope implements HttpRequestFilter {
|
||||
|
||||
private final String SOAP_PREFIX
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
|
||||
private final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
|
||||
|
||||
|
|
|
@ -16,23 +16,14 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public abstract class BaseProfitBricksResponseHandler<T> extends ParseSax.HandlerForGeneratedRequestWithResult<T> {
|
||||
|
||||
protected final DateCodec dateCodec;
|
||||
|
||||
private final StringBuilder strBuilder;
|
||||
|
||||
public BaseProfitBricksResponseHandler(DateCodecFactory dateCodec) {
|
||||
this.dateCodec = checkNotNull(checkNotNull(dateCodec, "dateCodecFactory null").iso8601(), "iso8601 date codec null");
|
||||
public BaseProfitBricksResponseHandler() {
|
||||
this.strBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
|
@ -41,10 +32,6 @@ public abstract class BaseProfitBricksResponseHandler<T> extends ParseSax.Handle
|
|||
strBuilder.append(ch, start, length);
|
||||
}
|
||||
|
||||
protected final Date textToIso8601Date() {
|
||||
return dateCodec.toDate(textToStringValue());
|
||||
}
|
||||
|
||||
protected String textToStringValue() {
|
||||
return strBuilder.toString().trim();
|
||||
}
|
||||
|
@ -52,9 +39,9 @@ public abstract class BaseProfitBricksResponseHandler<T> extends ParseSax.Handle
|
|||
protected Float textToFloatValue() {
|
||||
return Float.valueOf(textToStringValue());
|
||||
}
|
||||
|
||||
protected Double textToDoubleValue(){
|
||||
return Double.valueOf( textToStringValue());
|
||||
|
||||
protected Double textToDoubleValue() {
|
||||
return Double.valueOf(textToStringValue());
|
||||
}
|
||||
|
||||
protected int textToIntValue() {
|
||||
|
|
|
@ -16,28 +16,24 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class RequestIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||
|
||||
private String requestId;
|
||||
|
||||
@Inject
|
||||
RequestIdOnlyResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
RequestIdOnlyResponseHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
setPropertyOnEndTag( qName );
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag( String qName ) {
|
||||
if ( "requestId".equals( qName ) )
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("requestId".equals(qName))
|
||||
requestId = textToStringValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,42 +16,37 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.ServiceFault;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class ServiceFaultResponseHandler extends BaseProfitBricksResponseHandler<ServiceFault> {
|
||||
|
||||
private final ServiceFault.Builder builder;
|
||||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
ServiceFaultResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
ServiceFaultResponseHandler() {
|
||||
this.builder = ServiceFault.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("faultCode".equals(qName))
|
||||
builder.faultCode(ServiceFault.FaultCode.fromValue(textToStringValue()));
|
||||
builder.faultCode(ServiceFault.FaultCode.fromValue(textToStringValue()));
|
||||
else if ("httpCode".equals(qName))
|
||||
builder.httpCode(textToIntValue());
|
||||
builder.httpCode(textToIntValue());
|
||||
else if ("message".equals(qName))
|
||||
builder.message(textToStringValue());
|
||||
builder.message(textToStringValue());
|
||||
else if ("requestId".equals(qName))
|
||||
builder.requestId(textToIntValue());
|
||||
builder.requestId(textToIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (done)
|
||||
return;
|
||||
return;
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("detail".equals(qName))
|
||||
done = true;
|
||||
done = true;
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.datacenter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
|
||||
|
@ -26,18 +23,16 @@ public abstract class BaseDataCenterResponseHandler<T> extends BaseProfitBricksR
|
|||
|
||||
protected DataCenter.Builder builder;
|
||||
|
||||
@Inject
|
||||
BaseDataCenterResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
BaseDataCenterResponseHandler() {
|
||||
this.builder = DataCenter.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("dataCenterId".equals(qName))
|
||||
builder.id(textToStringValue());
|
||||
builder.id(textToStringValue());
|
||||
else if ("dataCenterVersion".equals(qName))
|
||||
builder.version(textToIntValue());
|
||||
builder.version(textToIntValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,42 +16,94 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.datacenter;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.http.parser.server.ServerInfoResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.storage.StorageInfoResponseHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class DataCenterInfoResponseHandler extends BaseDataCenterResponseHandler<DataCenter> {
|
||||
|
||||
private final ServerInfoResponseHandler serverInfoResponseHandler;
|
||||
private final StorageInfoResponseHandler storageInfoResponseHandler;
|
||||
|
||||
private final List<Server> servers = Lists.newArrayList();
|
||||
private final List<Storage> storages = Lists.newArrayList();
|
||||
|
||||
private boolean done = false;
|
||||
private boolean useServerParser = false;
|
||||
private boolean useStorageParser = false;
|
||||
|
||||
@Inject
|
||||
DataCenterInfoResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
DataCenterInfoResponseHandler(ServerInfoResponseHandler serverInfoResponseHandler, StorageInfoResponseHandler storageInforResponseHandler) {
|
||||
this.serverInfoResponseHandler = serverInfoResponseHandler;
|
||||
this.storageInfoResponseHandler = storageInforResponseHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if ("servers".equals(qName))
|
||||
useServerParser = true;
|
||||
else if ("storages".equals(qName))
|
||||
useStorageParser = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
super.setPropertyOnEndTag(qName);
|
||||
if ("dataCenterName".equals(qName))
|
||||
builder.name(textToStringValue());
|
||||
builder.name(textToStringValue());
|
||||
else if ("location".equals(qName))
|
||||
builder.location(Location.fromId(textToStringValue()));
|
||||
builder.location(Location.fromId(textToStringValue()));
|
||||
else if ("provisioningState".equals(qName))
|
||||
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (useServerParser)
|
||||
serverInfoResponseHandler.characters(ch, start, length);
|
||||
else if (useStorageParser)
|
||||
storageInfoResponseHandler.characters(ch, start, length);
|
||||
else
|
||||
super.characters(ch, start, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (done)
|
||||
return;
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName))
|
||||
done = true;
|
||||
clearTextBuffer();
|
||||
return;
|
||||
|
||||
if ("servers".equals(qName)) {
|
||||
useServerParser = false;
|
||||
servers.add(serverInfoResponseHandler.getResult());
|
||||
} else if ("storages".equals(qName)) {
|
||||
useStorageParser = false;
|
||||
storages.add(storageInfoResponseHandler.getResult());
|
||||
}
|
||||
|
||||
if (useServerParser)
|
||||
serverInfoResponseHandler.endElement(uri, localName, qName);
|
||||
else if (useStorageParser)
|
||||
storageInfoResponseHandler.endElement(uri, localName, qName);
|
||||
else {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
done = true;
|
||||
builder.servers(servers);
|
||||
builder.storages(storages);
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,22 +18,18 @@ package org.jclouds.profitbricks.http.parser.datacenter;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class DataCenterListResponseHandler extends BaseDataCenterResponseHandler<List<DataCenter>> {
|
||||
|
||||
private final List<DataCenter> dataCenters;
|
||||
|
||||
@Inject
|
||||
DataCenterListResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
DataCenterListResponseHandler() {
|
||||
this.dataCenters = Lists.newArrayList();
|
||||
}
|
||||
|
||||
|
@ -46,19 +42,19 @@ public class DataCenterListResponseHandler extends BaseDataCenterResponseHandler
|
|||
protected void setPropertyOnEndTag(String qName) {
|
||||
super.setPropertyOnEndTag(qName);
|
||||
if ("dataCenterName".equals(qName))
|
||||
builder.name(textToStringValue());
|
||||
builder.name(textToStringValue());
|
||||
else if ("location".equals(qName))
|
||||
builder.location(Location.fromValue(textToStringValue()));
|
||||
builder.location(Location.fromValue(textToStringValue()));
|
||||
else if ("provisioningState".equals(qName))
|
||||
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
dataCenters.add(builder.build());
|
||||
builder = DataCenter.builder();
|
||||
dataCenters.add(builder.build());
|
||||
builder = DataCenter.builder();
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.jclouds.profitbricks.domain.Image.Type;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
|
@ -29,9 +26,7 @@ public abstract class BaseImageResponseHandler<T> extends BaseProfitBricksRespon
|
|||
|
||||
protected Image.Builder builder;
|
||||
|
||||
@Inject
|
||||
BaseImageResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
BaseImageResponseHandler() {
|
||||
this.builder = Image.builder();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -25,9 +23,7 @@ public class ImageInfoResponseHandler extends BaseImageResponseHandler<Image> {
|
|||
|
||||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
ImageInfoResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
ImageInfoResponseHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -27,9 +27,7 @@ public class ImageListResponseHandler extends BaseImageResponseHandler<List<Imag
|
|||
|
||||
private final List<Image> images;
|
||||
|
||||
@Inject
|
||||
ImageListResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
ImageListResponseHandler() {
|
||||
this.images = Lists.newArrayList();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,12 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
|
@ -28,48 +33,54 @@ public abstract class BaseServerResponseHandler<T> extends BaseProfitBricksRespo
|
|||
|
||||
protected Server.DescribingBuilder builder;
|
||||
|
||||
protected final DateCodec dateCodec;
|
||||
|
||||
@Inject
|
||||
BaseServerResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
BaseServerResponseHandler(DateCodecFactory dateCodec) {
|
||||
this.dateCodec = dateCodec.iso8601();
|
||||
this.builder = Server.builder();
|
||||
}
|
||||
|
||||
protected final Date textToIso8601Date() {
|
||||
return dateCodec.toDate(textToStringValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag( String qName ) {
|
||||
if ( "serverId".equals( qName ) )
|
||||
builder.id( textToStringValue() );
|
||||
else if ( "serverName".equals( qName ) )
|
||||
builder.name( textToStringValue() );
|
||||
else if ( "cores".equals( qName ) )
|
||||
builder.cores( textToIntValue() );
|
||||
else if ( "ram".equals( qName ) )
|
||||
builder.ram( textToIntValue() );
|
||||
else if ( "provisioningState".equals( qName ) )
|
||||
builder.state( ProvisioningState.fromValue( textToStringValue() ) );
|
||||
else if ( "virtualMachineState".equals( qName ) )
|
||||
builder.status( Server.Status.fromValue( textToStringValue() ) );
|
||||
else if ( "osType".equals( qName ) )
|
||||
builder.osType( OsType.fromValue( textToStringValue() ) );
|
||||
else if ( "availabilityZone".equals( qName ) )
|
||||
builder.availabilityZone( AvailabilityZone.fromValue( textToStringValue() ) );
|
||||
else if ( "creationTime".equals( qName ) )
|
||||
builder.creationTime( textToIso8601Date() );
|
||||
else if ( "lastModificationTime".equals( qName ) )
|
||||
builder.lastModificationTime( textToIso8601Date() );
|
||||
else if ( "internetAccess".equals( qName ) )
|
||||
builder.hasInternetAccess( textToBooleanValue() );
|
||||
else if ( "cpuHotPlug".equals( qName ) )
|
||||
builder.isCpuHotPlug( textToBooleanValue() );
|
||||
else if ( "ramHotPlug".equals( qName ) )
|
||||
builder.isRamHotPlug( textToBooleanValue() );
|
||||
else if ( "nicHotPlug".equals( qName ) )
|
||||
builder.isNicHotPlug( textToBooleanValue() );
|
||||
else if ( "nicHotUnPlug".equals( qName ) )
|
||||
builder.isNicHotUnPlug( textToBooleanValue() );
|
||||
else if ( "discVirtioHotPlug".equals( qName ) )
|
||||
builder.isDiscVirtioHotPlug( textToBooleanValue() );
|
||||
else if ( "discVirtioHotUnPlug".equals( qName ) )
|
||||
builder.isDiscVirtioHotUnPlug( textToBooleanValue() );
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("serverId".equals(qName))
|
||||
builder.id(textToStringValue());
|
||||
else if ("serverName".equals(qName))
|
||||
builder.name(textToStringValue());
|
||||
else if ("cores".equals(qName))
|
||||
builder.cores(textToIntValue());
|
||||
else if ("ram".equals(qName))
|
||||
builder.ram(textToIntValue());
|
||||
else if ("provisioningState".equals(qName))
|
||||
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||
else if ("virtualMachineState".equals(qName))
|
||||
builder.status(Server.Status.fromValue(textToStringValue()));
|
||||
else if ("osType".equals(qName))
|
||||
builder.osType(OsType.fromValue(textToStringValue()));
|
||||
else if ("availabilityZone".equals(qName))
|
||||
builder.availabilityZone(AvailabilityZone.fromValue(textToStringValue()));
|
||||
else if ("creationTime".equals(qName))
|
||||
builder.creationTime(textToIso8601Date());
|
||||
else if ("lastModificationTime".equals(qName))
|
||||
builder.lastModificationTime(textToIso8601Date());
|
||||
else if ("internetAccess".equals(qName))
|
||||
builder.hasInternetAccess(textToBooleanValue());
|
||||
else if ("cpuHotPlug".equals(qName))
|
||||
builder.isCpuHotPlug(textToBooleanValue());
|
||||
else if ("ramHotPlug".equals(qName))
|
||||
builder.isRamHotPlug(textToBooleanValue());
|
||||
else if ("nicHotPlug".equals(qName))
|
||||
builder.isNicHotPlug(textToBooleanValue());
|
||||
else if ("nicHotUnPlug".equals(qName))
|
||||
builder.isNicHotUnPlug(textToBooleanValue());
|
||||
else if ("discVirtioHotPlug".equals(qName))
|
||||
builder.isDiscVirtioHotPlug(textToBooleanValue());
|
||||
else if ("discVirtioHotUnPlug".equals(qName))
|
||||
builder.isDiscVirtioHotUnPlug(textToBooleanValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -30,20 +28,18 @@ public class ServerIdOnlyResponseHandler extends BaseProfitBricksResponseHandler
|
|||
|
||||
private String serverId;
|
||||
|
||||
@Inject
|
||||
ServerIdOnlyResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
ServerIdOnlyResponseHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
setPropertyOnEndTag( qName );
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag( String qName ) {
|
||||
if ( "serverId".equals( qName ) )
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("serverId".equals(qName))
|
||||
serverId = textToStringValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ public class ServerInfoResponseHandler extends BaseServerResponseHandler<Server>
|
|||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
ServerInfoResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
ServerInfoResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
if ( done )
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (done)
|
||||
return;
|
||||
setPropertyOnEndTag( qName );
|
||||
if ( "return".equals( qName ) )
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName))
|
||||
done = true;
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
|
|
@ -28,16 +28,16 @@ public class ServerListResponseHandler extends BaseServerResponseHandler<List<Se
|
|||
private final List<Server> servers;
|
||||
|
||||
@Inject
|
||||
ServerListResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
ServerListResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
this.servers = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
setPropertyOnEndTag( qName );
|
||||
if ( "return".equals( qName ) ) {
|
||||
servers.add( builder.build() );
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
servers.add(builder.build());
|
||||
builder = Server.builder();
|
||||
}
|
||||
clearTextBuffer();
|
||||
|
|
|
@ -16,20 +16,15 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.state;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class GetProvisioningStateResponseHandler extends BaseProfitBricksResponseHandler<ProvisioningState> {
|
||||
|
||||
private ProvisioningState state = ProvisioningState.UNRECOGNIZED;
|
||||
|
||||
@Inject
|
||||
GetProvisioningStateResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
GetProvisioningStateResponseHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,7 +36,7 @@ public class GetProvisioningStateResponseHandler extends BaseProfitBricksRespons
|
|||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("return".equals(qName))
|
||||
state = ProvisioningState.fromValue(textToStringValue());
|
||||
state = ProvisioningState.fromValue(textToStringValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.domain.Storage.BusType;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public abstract class BaseStorageResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||
|
||||
protected final DateCodec dateCodec;
|
||||
|
||||
protected Storage.Builder builder;
|
||||
protected List<String> serverIds;
|
||||
|
||||
@Inject
|
||||
BaseStorageResponseHandler(DateCodecFactory dateCodec) {
|
||||
this.dateCodec = dateCodec.iso8601();
|
||||
this.builder = Storage.builder();
|
||||
this.serverIds = Lists.newArrayList();
|
||||
}
|
||||
|
||||
protected final Date textToIso8601Date() {
|
||||
return dateCodec.toDate(textToStringValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
// <requestId>?</requestId>
|
||||
// <dataCenterId>?</dataCenterId>
|
||||
// <dataCenterVersion>?</dataCenterVersion>
|
||||
if ("storageId".equals(qName))
|
||||
builder.id(textToStringValue());
|
||||
else if ("size".equals(qName))
|
||||
builder.size(textToFloatValue());
|
||||
else if ("storageName".equals(qName))
|
||||
builder.name(textToStringValue());
|
||||
else if ("provisioningState".equals(qName))
|
||||
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||
else if ("creationTime".equals(qName))
|
||||
builder.creationTime(textToIso8601Date());
|
||||
else if ("lastModificationTime".equals(qName))
|
||||
builder.lastModificationTime(textToIso8601Date());
|
||||
// <mountImage>
|
||||
// <imageId>?</imageId>
|
||||
// <imageName>?</imageName>
|
||||
// </mountImage>
|
||||
else if ("serverIds".equals(qName))
|
||||
serverIds.add(textToStringValue());
|
||||
else if ("bootDevice".equals(qName))
|
||||
builder.bootDevice(textToBooleanValue());
|
||||
else if ("busType".equals(qName))
|
||||
builder.busType(BusType.fromValue(textToStringValue()));
|
||||
else if ("deviceNumber".equals(qName))
|
||||
builder.deviceNumber(textToIntValue());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class StorageIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||
|
||||
private String storageId;
|
||||
|
||||
StorageIdOnlyResponseHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("storageId".equals(qName))
|
||||
storageId = textToStringValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
return storageId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class StorageInfoResponseHandler extends BaseStorageResponseHandler<Storage> {
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
StorageInfoResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (done)
|
||||
return;
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
done = true;
|
||||
builder.serverIds(serverIds);
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage getResult() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import autovalue.shaded.com.google.common.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class StorageListResponseHandler extends BaseStorageResponseHandler<List<Storage>> {
|
||||
|
||||
private final List<Storage> storages;
|
||||
|
||||
@Inject
|
||||
StorageListResponseHandler(DateCodecFactory dateCodec) {
|
||||
super(dateCodec);
|
||||
this.storages = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
storages.add(builder
|
||||
.serverIds(serverIds)
|
||||
.build());
|
||||
builder = Storage.builder();
|
||||
serverIds = Lists.newArrayList();
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Storage> getResult() {
|
||||
return storages;
|
||||
}
|
||||
|
||||
}
|
|
@ -38,8 +38,8 @@ public abstract class BaseProfitBricksLiveTest extends BaseApiLiveTest<ProfitBri
|
|||
protected void initialize() {
|
||||
super.initialize();
|
||||
this.dcWaitingPredicate = Predicates2.retry(
|
||||
new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.DATACENTER, ProvisioningState.AVAILABLE),
|
||||
2l * 60l, 2l, TimeUnit.SECONDS);
|
||||
new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.DATACENTER, ProvisioningState.AVAILABLE),
|
||||
2l * 60l, 2l, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ public class CreateDataCenterRequestBinderTest {
|
|||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= (" <ws:createDataCenter>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterName>JClouds-DC</dataCenterName>\n"
|
||||
+ " <location>de/fkb</location>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:createDataCenter>\n").replaceAll("\\s+", "");
|
||||
= (" <ws:createDataCenter>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterName>JClouds-DC</dataCenterName>\n"
|
||||
+ " <location>de/fkb</location>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:createDataCenter>\n").replaceAll("\\s+", "");
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ public class UpdateDataCenterRequestBinderTest {
|
|||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= (" <ws:updateDataCenter>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n"
|
||||
+ " <dataCenterName>Apache-DC</dataCenterName>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:updateDataCenter>").replaceAll("\\s+", "");
|
||||
= (" <ws:updateDataCenter>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n"
|
||||
+ " <dataCenterName>Apache-DC</dataCenterName>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:updateDataCenter>").replaceAll("\\s+", "");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "CreateServerRequestBinderTest" )
|
||||
@Test(groups = "unit", testName = "CreateServerRequestBinderTest")
|
||||
public class CreateServerRequestBinderTest {
|
||||
|
||||
@Test
|
||||
|
@ -29,37 +29,37 @@ public class CreateServerRequestBinderTest {
|
|||
CreateServerRequestBinder binder = new CreateServerRequestBinder();
|
||||
|
||||
Server.Request.CreatePayload payload = Server.Request.creatingBuilder()
|
||||
.name( "jclouds-node" )
|
||||
.cores( 4 )
|
||||
.ram( 4 * 1024 )
|
||||
.dataCenterId( "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" )
|
||||
.name("jclouds-node")
|
||||
.cores(4)
|
||||
.ram(4 * 1024)
|
||||
.dataCenterId("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload( payload );
|
||||
assertNotNull( actual, "Binder returned null payload" );
|
||||
assertEquals( actual, expectedPayload );
|
||||
String actual = binder.createPayload(payload);
|
||||
assertNotNull(actual, "Binder returned null payload");
|
||||
assertEquals(actual, expectedPayload);
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= ( " <ws:createServer>\n"
|
||||
= (" <ws:createServer>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n"
|
||||
+ " <cores>4</cores>\n"
|
||||
+ " <ram>4096</ram>\n"
|
||||
+ " <serverName>jclouds-node</serverName>\n"
|
||||
// + " <bootFromStorageId>?</bootFromStorageId>\n"
|
||||
// + " <bootFromImageId>?</bootFromImageId>\n"
|
||||
// + " <internetAccess>false</internetAccess>\n"
|
||||
// + " <lanId>?</lanId>\n"
|
||||
// + " <osType>?</osType>\n"
|
||||
// + " <availabilityZone>AUTO</availabilityZone>\n"
|
||||
// + " <cpuHotPlug>false</cpuHotPlug>\n"
|
||||
// + " <ramHotPlug>false</ramHotPlug>\n"
|
||||
// + " <nicHotPlug>false</nicHotPlug>\n"
|
||||
// + " <nicHotUnPlug>false</nicHotUnPlug>\n"
|
||||
// + " <discVirtioHotPlug>false</discVirtioHotPlug>\n"
|
||||
// + " <discVirtioHotUnPlug>false</discVirtioHotUnPlug>\n"
|
||||
// + " <bootFromStorageId>?</bootFromStorageId>\n"
|
||||
// + " <bootFromImageId>?</bootFromImageId>\n"
|
||||
// + " <internetAccess>false</internetAccess>\n"
|
||||
// + " <lanId>?</lanId>\n"
|
||||
// + " <osType>?</osType>\n"
|
||||
// + " <availabilityZone>AUTO</availabilityZone>\n"
|
||||
// + " <cpuHotPlug>false</cpuHotPlug>\n"
|
||||
// + " <ramHotPlug>false</ramHotPlug>\n"
|
||||
// + " <nicHotPlug>false</nicHotPlug>\n"
|
||||
// + " <nicHotUnPlug>false</nicHotUnPlug>\n"
|
||||
// + " <discVirtioHotPlug>false</discVirtioHotPlug>\n"
|
||||
// + " <discVirtioHotUnPlug>false</discVirtioHotUnPlug>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:createServer>" )
|
||||
.replaceAll( "\\s+", "" );
|
||||
+ " </ws:createServer>")
|
||||
.replaceAll("\\s+", "");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "UpdateServerRequestBinderTest" )
|
||||
@Test(groups = "unit", testName = "UpdateServerRequestBinderTest")
|
||||
public class UpdateServerRequestBinderTest {
|
||||
|
||||
@Test
|
||||
|
@ -29,36 +29,36 @@ public class UpdateServerRequestBinderTest {
|
|||
UpdateServerRequestBinder binder = new UpdateServerRequestBinder();
|
||||
|
||||
Server.Request.UpdatePayload payload = Server.Request.updatingBuilder()
|
||||
.id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" )
|
||||
.cores( 8 )
|
||||
.ram( 8 * 1024 )
|
||||
.name( "apache-node")
|
||||
.id("qwertyui-qwer-qwer-qwer-qwertyyuiiop")
|
||||
.cores(8)
|
||||
.ram(8 * 1024)
|
||||
.name("apache-node")
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload( payload );
|
||||
|
||||
String actual = binder.createPayload(payload);
|
||||
assertNotNull(actual, "Binder returned null payload");
|
||||
assertEquals(actual, expectedPayload);
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= ( " <ws:updateServer>\n"
|
||||
= (" <ws:updateServer>\n"
|
||||
+ " <request>\n"
|
||||
+ " <serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>\n"
|
||||
+ " <cores>8</cores>\n"
|
||||
+ " <ram>8192</ram>\n"
|
||||
+ " <serverName>apache-node</serverName>\n"
|
||||
// + " <bootFromStorageId>?</bootFromStorageId>\n"
|
||||
// + " <bootFromImageId>?</bootFromImageId>\n"
|
||||
// + " <osType>?</osType>\n"
|
||||
// + " <availabilityZone>?</availabilityZone>\n"
|
||||
// + " <cpuHotPlug>?</cpuHotPlug>\n"
|
||||
// + " <ramHotPlug>?</ramHotPlug>\n"
|
||||
// + " <nicHotPlug>?</nicHotPlug>\n"
|
||||
// + " <nicHotUnPlug>?</nicHotUnPlug>\n"
|
||||
// + " <discVirtioHotPlug>?</discVirtioHotPlug>\n"
|
||||
// + " <discVirtioHotUnPlug>?</discVirtioHotUnPlug>\n"
|
||||
// + " <bootFromStorageId>?</bootFromStorageId>\n"
|
||||
// + " <bootFromImageId>?</bootFromImageId>\n"
|
||||
// + " <osType>?</osType>\n"
|
||||
// + " <availabilityZone>?</availabilityZone>\n"
|
||||
// + " <cpuHotPlug>?</cpuHotPlug>\n"
|
||||
// + " <ramHotPlug>?</ramHotPlug>\n"
|
||||
// + " <nicHotPlug>?</nicHotPlug>\n"
|
||||
// + " <nicHotUnPlug>?</nicHotUnPlug>\n"
|
||||
// + " <discVirtioHotPlug>?</discVirtioHotPlug>\n"
|
||||
// + " <discVirtioHotUnPlug>?</discVirtioHotUnPlug>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:updateServer>" )
|
||||
.replaceAll( "\\s+", "" );
|
||||
+ " </ws:updateServer>")
|
||||
.replaceAll("\\s+", "");
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.storage;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "unit", testName = "ConnectStorageToServerRequestBinderTest")
|
||||
public class ConnectStorageToServerRequestBinderTest {
|
||||
|
||||
@Test
|
||||
public void testCreatePayload() {
|
||||
ConnectStorageToServerRequestBinder binder = new ConnectStorageToServerRequestBinder();
|
||||
|
||||
Storage.Request.ConnectPayload payload = Storage.Request.connectingBuilder()
|
||||
.serverId("qwertyui-qwer-qwer-qwer-qwertyyuiiop")
|
||||
.storageId("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh")
|
||||
.busType(Storage.BusType.VIRTIO)
|
||||
.deviceNumber(2)
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload(payload);
|
||||
assertNotNull(actual, "Binder returned null payload");
|
||||
assertEquals(actual, expectedPayload);
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= (" <ws:connectStorageToServer>\n"
|
||||
+ " <request>\n"
|
||||
+ " <storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>\n"
|
||||
+ " <serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>\n"
|
||||
+ " <busType>VIRTIO</busType>\n"
|
||||
+ " <deviceNumber>2</deviceNumber>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:connectStorageToServer>")
|
||||
.replaceAll("\\s+", "");
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.storage;
|
||||
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "unit", testName = "CreateStorageRequestBinderTest")
|
||||
public class CreateStorageRequestBinderTest {
|
||||
|
||||
@Test
|
||||
public void testCreatePayload() {
|
||||
CreateStorageRequestBinder binder = new CreateStorageRequestBinder();
|
||||
|
||||
Storage.Request.CreatePayload payload = Storage.Request.creatingBuilder()
|
||||
.name("hdd-1")
|
||||
.size(60f)
|
||||
.dataCenterId("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
|
||||
.mountImageId("5ad99c9e-9166-11e4-9d74-52540066fee9")
|
||||
.imagePassword("qqqqqqqqq")
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload(payload);
|
||||
assertNotNull(actual, "Binder returned null payload");
|
||||
assertEquals(actual, expectedPayload);
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= (" <ws:createStorage>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n"
|
||||
+ " <storageName>hdd-1</storageName>\n"
|
||||
+ " <size>60</size>\n"
|
||||
+ " <mountImageId>5ad99c9e-9166-11e4-9d74-52540066fee9</mountImageId>\n"
|
||||
+ " <profitBricksImagePassword>qqqqqqqqq</profitBricksImagePassword>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:createStorage>")
|
||||
.replaceAll("\\s+", "");
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.storage;
|
||||
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "unit", testName = "UpdateStorageRequestBinderTest")
|
||||
public class UpdateStorageRequestBinderTest {
|
||||
|
||||
@Test
|
||||
public void testUpdatePayload() {
|
||||
UpdateStorageRequestBinder binder = new UpdateStorageRequestBinder();
|
||||
|
||||
Storage.Request.UpdatePayload payload = Storage.Request.updatingBuilder()
|
||||
.id("pppppppp-llkl-kkjk-fhgh-vnmegrdgdsgr")
|
||||
.size(100f)
|
||||
.name("hdd-2")
|
||||
.mountImageId("5f3cac96-915f-11e4-9d74-52540066fee9")
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload(payload);
|
||||
assertNotNull(actual, "Binder returned null payload");
|
||||
assertEquals(actual, expectedPayload);
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= (" <ws:updateStorage>\n"
|
||||
+ " <request>\n"
|
||||
+ " <storageId>pppppppp-llkl-kkjk-fhgh-vnmegrdgdsgr</storageId>\n"
|
||||
+ " <size>100</size>\n"
|
||||
+ " <storageName>hdd-2</storageName>\n"
|
||||
+ " <mountImageId>5f3cac96-915f-11e4-9d74-52540066fee9</mountImageId>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:updateStorage>")
|
||||
.replaceAll("\\s+", "");
|
||||
}
|
|
@ -39,7 +39,7 @@ import com.squareup.okhttp.mockwebserver.MockWebServer;
|
|||
public class ProvisioningStatusPollingPredicateTest extends BaseProfitBricksMockTest {
|
||||
|
||||
@Test
|
||||
public void testPredicate() throws Exception {
|
||||
public void testDataCenterPredicate() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
|
||||
byte[] payloadInProcess = payloadFromResource("/datacenter/datacenter-state-inprocess.xml");
|
||||
|
@ -71,4 +71,70 @@ public class ProvisioningStatusPollingPredicateTest extends BaseProfitBricksMock
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerPredicate() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
|
||||
byte[] payloadInProcess = payloadFromResource("/server/server-state-inprocess.xml");
|
||||
byte[] payloadAvailable = payloadFromResource("/server/server.xml");
|
||||
|
||||
// wait 3 times
|
||||
server.enqueue(new MockResponse().setBody(payloadInProcess));
|
||||
server.enqueue(new MockResponse().setBody(payloadInProcess));
|
||||
server.enqueue(new MockResponse().setBody(payloadInProcess));
|
||||
server.enqueue(new MockResponse().setBody(payloadAvailable));
|
||||
|
||||
server.enqueue(new MockResponse().setBody(payloadAvailable));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
|
||||
Predicate<String> waitUntilAvailable = Predicates2.retry(
|
||||
new ProvisioningStatusPollingPredicate(pbApi, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE),
|
||||
30l, 1l, TimeUnit.SECONDS);
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
try {
|
||||
waitUntilAvailable.apply(id);
|
||||
ProvisioningState finalState = pbApi.serverApi().getServer(id).state();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertEquals(finalState, ProvisioningState.AVAILABLE);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoragePredicate() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
|
||||
byte[] payloadInProcess = payloadFromResource("/storage/storage-state-inprocess.xml");
|
||||
byte[] payloadAvailable = payloadFromResource("/storage/storage.xml");
|
||||
|
||||
// wait 3 times
|
||||
server.enqueue(new MockResponse().setBody(payloadInProcess));
|
||||
server.enqueue(new MockResponse().setBody(payloadInProcess));
|
||||
server.enqueue(new MockResponse().setBody(payloadInProcess));
|
||||
server.enqueue(new MockResponse().setBody(payloadAvailable));
|
||||
|
||||
server.enqueue(new MockResponse().setBody(payloadAvailable));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
|
||||
Predicate<String> waitUntilAvailable = Predicates2.retry(
|
||||
new ProvisioningStatusPollingPredicate(pbApi, ProvisioningStatusAware.STORAGE, ProvisioningState.AVAILABLE),
|
||||
30l, 1l, TimeUnit.SECONDS);
|
||||
|
||||
String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
|
||||
try {
|
||||
waitUntilAvailable.apply(id);
|
||||
ProvisioningState finalState = pbApi.storageApi().getStorage(id).state();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertEquals(finalState, ProvisioningState.AVAILABLE);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Date;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerBuilderTest" )
|
||||
@Test(groups = "unit", testName = "ServerBuilderTest")
|
||||
public class ServerBuilderTest {
|
||||
|
||||
private final Boolean _isCpuHotPlug = true;
|
||||
|
@ -46,119 +46,117 @@ public class ServerBuilderTest {
|
|||
private final String _bootFromStorageId = "some-random-storage-id";
|
||||
private final String _bootFromImageId = "some-random-image-id";
|
||||
|
||||
private final String _serverId = "some-random-server-id";
|
||||
|
||||
@Test
|
||||
public void testAutoValueServerPropertiesSettingCorrectly() {
|
||||
Server actual = Server.builder()
|
||||
.availabilityZone( _availabilityZone )
|
||||
.creationTime( _creationTime )
|
||||
.cores( _cores )
|
||||
.hasInternetAccess( _hasInternetAccess )
|
||||
.id( _id )
|
||||
.name( _name )
|
||||
.isCpuHotPlug( _isCpuHotPlug )
|
||||
.isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
|
||||
.isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
|
||||
.isNicHotPlug( _isNicHotPlug )
|
||||
.isNicHotUnPlug( _isNicHotUnPlug )
|
||||
.isRamHotPlug( _isRamHotPlug )
|
||||
.lastModificationTime( _lastModificationTime )
|
||||
.ram( _ram )
|
||||
.osType( _osType )
|
||||
.state( _state )
|
||||
.status( _status )
|
||||
.availabilityZone(_availabilityZone)
|
||||
.creationTime(_creationTime)
|
||||
.cores(_cores)
|
||||
.hasInternetAccess(_hasInternetAccess)
|
||||
.id(_id)
|
||||
.name(_name)
|
||||
.isCpuHotPlug(_isCpuHotPlug)
|
||||
.isDiscVirtioHotPlug(_isDiscVirtioHotPlug)
|
||||
.isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug)
|
||||
.isNicHotPlug(_isNicHotPlug)
|
||||
.isNicHotUnPlug(_isNicHotUnPlug)
|
||||
.isRamHotPlug(_isRamHotPlug)
|
||||
.lastModificationTime(_lastModificationTime)
|
||||
.ram(_ram)
|
||||
.osType(_osType)
|
||||
.state(_state)
|
||||
.status(_status)
|
||||
.build();
|
||||
|
||||
assertEquals( actual.availabilityZone(), _availabilityZone );
|
||||
assertEquals( actual.cores(), _cores );
|
||||
assertEquals( actual.creationTime(), _creationTime );
|
||||
assertEquals( actual.hasInternetAccess(), _hasInternetAccess );
|
||||
assertEquals( actual.id(), _id );
|
||||
assertEquals( actual.name(), _name );
|
||||
assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
|
||||
assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
|
||||
assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
|
||||
assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
|
||||
assertEquals( actual.lastModificationTime(), _lastModificationTime );
|
||||
assertEquals( actual.ram(), _ram );
|
||||
assertEquals( actual.osType(), _osType );
|
||||
assertEquals( actual.state(), _state );
|
||||
assertEquals(actual.availabilityZone(), _availabilityZone);
|
||||
assertEquals(actual.cores(), _cores);
|
||||
assertEquals(actual.creationTime(), _creationTime);
|
||||
assertEquals(actual.hasInternetAccess(), _hasInternetAccess);
|
||||
assertEquals(actual.id(), _id);
|
||||
assertEquals(actual.name(), _name);
|
||||
assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug);
|
||||
assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug);
|
||||
assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug);
|
||||
assertEquals(actual.isNicHotPlug(), _isNicHotPlug);
|
||||
assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug);
|
||||
assertEquals(actual.isRamHotPlug(), _isRamHotPlug);
|
||||
assertEquals(actual.lastModificationTime(), _lastModificationTime);
|
||||
assertEquals(actual.ram(), _ram);
|
||||
assertEquals(actual.osType(), _osType);
|
||||
assertEquals(actual.state(), _state);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoValueServerRequestCreatePayloadPropertiesSettingCorrectly() {
|
||||
Server.Request.CreatePayload actual = Server.Request.creatingBuilder()
|
||||
.availabilityZone( _availabilityZone )
|
||||
.bootFromImageId( _bootFromImageId )
|
||||
.bootFromStorageId( _bootFromStorageId )
|
||||
.cores( _cores )
|
||||
.dataCenterId( _dataCenterId )
|
||||
.hasInternetAccess( _hasInternetAccess )
|
||||
.name( _name )
|
||||
.isCpuHotPlug( _isCpuHotPlug )
|
||||
.isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
|
||||
.isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
|
||||
.isNicHotPlug( _isNicHotPlug )
|
||||
.isNicHotUnPlug( _isNicHotUnPlug )
|
||||
.isRamHotPlug( _isRamHotPlug )
|
||||
.lanId( _lanId )
|
||||
.ram( _ram )
|
||||
.osType( _osType )
|
||||
.availabilityZone(_availabilityZone)
|
||||
.bootFromImageId(_bootFromImageId)
|
||||
.bootFromStorageId(_bootFromStorageId)
|
||||
.cores(_cores)
|
||||
.dataCenterId(_dataCenterId)
|
||||
.hasInternetAccess(_hasInternetAccess)
|
||||
.name(_name)
|
||||
.isCpuHotPlug(_isCpuHotPlug)
|
||||
.isDiscVirtioHotPlug(_isDiscVirtioHotPlug)
|
||||
.isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug)
|
||||
.isNicHotPlug(_isNicHotPlug)
|
||||
.isNicHotUnPlug(_isNicHotUnPlug)
|
||||
.isRamHotPlug(_isRamHotPlug)
|
||||
.lanId(_lanId)
|
||||
.ram(_ram)
|
||||
.osType(_osType)
|
||||
.build();
|
||||
|
||||
assertEquals( actual.availabilityZone(), _availabilityZone );
|
||||
assertEquals( actual.bootFromImageId(), _bootFromImageId );
|
||||
assertEquals( actual.bootFromStorageId(), _bootFromStorageId );
|
||||
assertEquals( actual.cores(), _cores );
|
||||
assertEquals( actual.dataCenterId(), _dataCenterId );
|
||||
assertEquals( actual.hasInternetAccess(), _hasInternetAccess );
|
||||
assertEquals( actual.name(), _name );
|
||||
assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
|
||||
assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
|
||||
assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
|
||||
assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
|
||||
assertEquals( actual.lanId(), _lanId );
|
||||
assertEquals( actual.ram(), _ram );
|
||||
assertEquals( actual.osType(), _osType );
|
||||
assertEquals(actual.availabilityZone(), _availabilityZone);
|
||||
assertEquals(actual.bootFromImageId(), _bootFromImageId);
|
||||
assertEquals(actual.bootFromStorageId(), _bootFromStorageId);
|
||||
assertEquals(actual.cores(), _cores);
|
||||
assertEquals(actual.dataCenterId(), _dataCenterId);
|
||||
assertEquals(actual.hasInternetAccess(), _hasInternetAccess);
|
||||
assertEquals(actual.name(), _name);
|
||||
assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug);
|
||||
assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug);
|
||||
assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug);
|
||||
assertEquals(actual.isNicHotPlug(), _isNicHotPlug);
|
||||
assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug);
|
||||
assertEquals(actual.isRamHotPlug(), _isRamHotPlug);
|
||||
assertEquals(actual.lanId(), _lanId);
|
||||
assertEquals(actual.ram(), _ram);
|
||||
assertEquals(actual.osType(), _osType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoValueServerRequestUpdatePayloadPropertiesSettingCorrectly() {
|
||||
Server.Request.UpdatePayload actual = Server.Request.updatingBuilder()
|
||||
.availabilityZone( _availabilityZone )
|
||||
.bootFromImageId( _bootFromImageId )
|
||||
.bootFromStorageId( _bootFromStorageId )
|
||||
.cores( _cores )
|
||||
.name( _name )
|
||||
.id( _id )
|
||||
.isCpuHotPlug( _isCpuHotPlug )
|
||||
.isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
|
||||
.isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
|
||||
.isNicHotPlug( _isNicHotPlug )
|
||||
.isNicHotUnPlug( _isNicHotUnPlug )
|
||||
.isRamHotPlug( _isRamHotPlug )
|
||||
.ram( _ram )
|
||||
.osType( _osType )
|
||||
.availabilityZone(_availabilityZone)
|
||||
.bootFromImageId(_bootFromImageId)
|
||||
.bootFromStorageId(_bootFromStorageId)
|
||||
.cores(_cores)
|
||||
.name(_name)
|
||||
.id(_id)
|
||||
.isCpuHotPlug(_isCpuHotPlug)
|
||||
.isDiscVirtioHotPlug(_isDiscVirtioHotPlug)
|
||||
.isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug)
|
||||
.isNicHotPlug(_isNicHotPlug)
|
||||
.isNicHotUnPlug(_isNicHotUnPlug)
|
||||
.isRamHotPlug(_isRamHotPlug)
|
||||
.ram(_ram)
|
||||
.osType(_osType)
|
||||
.build();
|
||||
|
||||
assertEquals( actual.availabilityZone(), _availabilityZone );
|
||||
assertEquals( actual.bootFromImageId(), _bootFromImageId );
|
||||
assertEquals( actual.bootFromStorageId(), _bootFromStorageId );
|
||||
assertEquals( actual.cores(), _cores );
|
||||
assertEquals( actual.name(), _name );
|
||||
assertEquals( actual.id(), _id );
|
||||
assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
|
||||
assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
|
||||
assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
|
||||
assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
|
||||
assertEquals( actual.ram(), _ram );
|
||||
assertEquals( actual.osType(), _osType );
|
||||
assertEquals(actual.availabilityZone(), _availabilityZone);
|
||||
assertEquals(actual.bootFromImageId(), _bootFromImageId);
|
||||
assertEquals(actual.bootFromStorageId(), _bootFromStorageId);
|
||||
assertEquals(actual.cores(), _cores);
|
||||
assertEquals(actual.name(), _name);
|
||||
assertEquals(actual.id(), _id);
|
||||
assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug);
|
||||
assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug);
|
||||
assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug);
|
||||
assertEquals(actual.isNicHotPlug(), _isNicHotPlug);
|
||||
assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug);
|
||||
assertEquals(actual.isRamHotPlug(), _isRamHotPlug);
|
||||
assertEquals(actual.ram(), _ram);
|
||||
assertEquals(actual.osType(), _osType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
String content = "<ws:getDataCenter><dataCenterId>" + id + "</dataCenterId></ws:getDataCenter>";
|
||||
try {
|
||||
DataCenter dataCenter = api.getDataCenter(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content );
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(dataCenter);
|
||||
assertEquals(dataCenter.id(), id);
|
||||
} finally {
|
||||
|
@ -130,7 +130,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
String content = "<ws:getDataCenterState><dataCenterId>" + id + "</dataCenterId></ws:getDataCenterState>";
|
||||
try {
|
||||
ProvisioningState state = api.getDataCenterState(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content );
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(state);
|
||||
assertEquals(state, ProvisioningState.AVAILABLE);
|
||||
} finally {
|
||||
|
@ -155,7 +155,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
DataCenter dataCenter = api.createDataCenter(
|
||||
DataCenter.Request.CreatePayload.create("JClouds-DC", Location.DE_FRA)
|
||||
);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content );
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(dataCenter);
|
||||
assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
|
||||
assertEquals(dataCenter.version(), 1);
|
||||
|
@ -168,14 +168,13 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testCreateDataCenterWithIllegalArguments() throws Exception {
|
||||
String[] names = {"JCl@ouds", "JC|ouds", "^clouds", ""};
|
||||
for (String name : names) {
|
||||
for (String name : names)
|
||||
try {
|
||||
DataCenter.Request.CreatePayload.create(name, Location.US_LAS);
|
||||
fail("Should have failed for name: ".concat(name));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -185,10 +184,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
String newName = "Apache";
|
||||
|
||||
|
||||
String content = "<ws:updateDataCenter><request>"
|
||||
+ "<dataCenterId>" + id + "</dataCenterId>"
|
||||
+ "<dataCenterName>" + newName + "</dataCenterName>"
|
||||
|
@ -216,7 +215,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
|
||||
|
||||
String content = "<ws:clearDataCenter><dataCenterId>" + id + "</dataCenterId></ws:clearDataCenter>";
|
||||
try {
|
||||
DataCenter dataCenter = api.clearDataCenter(id);
|
||||
|
@ -240,7 +239,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
|
||||
|
||||
String content = "<ws:deleteDataCenter><dataCenterId>" + id + "</dataCenterId></ws:deleteDataCenter>";
|
||||
try {
|
||||
boolean result = api.deleteDataCenter(id);
|
||||
|
@ -255,7 +254,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testDeleteNonExistingDataCenter() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode( 404 ));
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
|
|
@ -81,7 +81,7 @@ public class ImageApiMockTest extends BaseProfitBricksMockTest {
|
|||
ImageApi api = pbApi.imageApi();
|
||||
|
||||
String id = "5ad99c9e-9166-11e4-9d74-52540066fee9";
|
||||
|
||||
|
||||
String content = "<ws:getImage><imageId>" + id + "</imageId></ws:getImage>";
|
||||
try {
|
||||
Image image = api.getImage(id);
|
||||
|
|
|
@ -34,7 +34,7 @@ import static org.testng.Assert.assertTrue;
|
|||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "live", testName = "ServerApiLiveTest", singleThreaded = true )
|
||||
@Test(groups = "live", testName = "ServerApiLiveTest", singleThreaded = true)
|
||||
public class ServerApiLiveTest extends BaseProfitBricksLiveTest {
|
||||
|
||||
private Predicate<String> waitUntilAvailable;
|
||||
|
@ -45,94 +45,94 @@ public class ServerApiLiveTest extends BaseProfitBricksLiveTest {
|
|||
protected void initialize() {
|
||||
super.initialize();
|
||||
List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters();
|
||||
assertFalse( dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing." );
|
||||
assertFalse(dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing.");
|
||||
|
||||
this.dataCenter = Iterables.getFirst( dataCenters, null );
|
||||
this.dataCenter = Iterables.getFirst(dataCenters, null);
|
||||
|
||||
this.waitUntilAvailable = Predicates2.retry(
|
||||
new ProvisioningStatusPollingPredicate( api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE ),
|
||||
2l * 60l, 2l, TimeUnit.SECONDS );
|
||||
new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE),
|
||||
2l * 60l, 2l, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateServer() {
|
||||
String serverId = api.serverApi().createServer(
|
||||
Server.Request.CreatePayload.create( dataCenter.id(), "jclouds-node", 1, 1024 ) );
|
||||
Server.Request.CreatePayload.create(dataCenter.id(), "jclouds-node", 1, 1024));
|
||||
|
||||
assertNotNull( serverId );
|
||||
assertNotNull(serverId);
|
||||
this.createdServerId = serverId;
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testCreateServer" )
|
||||
@Test(dependsOnMethods = "testCreateServer")
|
||||
public void testGetServer() {
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
Server server = api.serverApi().getServer(createdServerId);
|
||||
|
||||
assertNotNull( server );
|
||||
assertEquals( server.id(), createdServerId );
|
||||
assertNotNull(server);
|
||||
assertEquals(server.id(), createdServerId);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testCreateServer" )
|
||||
@Test(dependsOnMethods = "testCreateServer")
|
||||
public void testGetAllServers() {
|
||||
List<Server> servers = api.serverApi().getAllServers();
|
||||
|
||||
assertNotNull( servers );
|
||||
assertFalse( servers.isEmpty() );
|
||||
assertNotNull(servers);
|
||||
assertFalse(servers.isEmpty());
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testCreateServer" )
|
||||
@Test(dependsOnMethods = "testCreateServer")
|
||||
public void testWaitUntilAvailable() {
|
||||
boolean available = waitUntilAvailable.apply( createdServerId );
|
||||
boolean available = waitUntilAvailable.apply(createdServerId);
|
||||
|
||||
assertTrue( available );
|
||||
assertTrue(available);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testWaitUntilAvailable" )
|
||||
@Test(dependsOnMethods = "testWaitUntilAvailable")
|
||||
public void testUpdateServer() {
|
||||
String requestId = api.serverApi().updateServer(
|
||||
Server.Request.updatingBuilder()
|
||||
.id( createdServerId )
|
||||
.name( "apache-node" )
|
||||
.cores( 2 )
|
||||
.ram( 2 * 1024 )
|
||||
.build() );
|
||||
.id(createdServerId)
|
||||
.name("apache-node")
|
||||
.cores(2)
|
||||
.ram(2 * 1024)
|
||||
.build());
|
||||
|
||||
assertNotNull( requestId );
|
||||
waitUntilAvailable.apply( createdServerId );
|
||||
assertNotNull(requestId);
|
||||
waitUntilAvailable.apply(createdServerId);
|
||||
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
assertEquals( server.state(), ProvisioningState.AVAILABLE );
|
||||
Server server = api.serverApi().getServer(createdServerId);
|
||||
assertEquals(server.state(), ProvisioningState.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testUpdateServer" )
|
||||
@Test(dependsOnMethods = "testUpdateServer")
|
||||
public void testStopServer() {
|
||||
String requestId = api.serverApi().stopServer( createdServerId );
|
||||
assertNotNull( requestId );
|
||||
String requestId = api.serverApi().stopServer(createdServerId);
|
||||
assertNotNull(requestId);
|
||||
|
||||
Predicate<String> waitUntilInactive = Predicates2.retry( new ProvisioningStatusPollingPredicate(
|
||||
api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE ), 2l * 60l, 2l, TimeUnit.SECONDS );
|
||||
Predicate<String> waitUntilInactive = Predicates2.retry(new ProvisioningStatusPollingPredicate(
|
||||
api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE), 2l * 60l, 2l, TimeUnit.SECONDS);
|
||||
|
||||
waitUntilInactive.apply( createdServerId );
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
assertEquals( server.status(), Server.Status.SHUTOFF );
|
||||
waitUntilInactive.apply(createdServerId);
|
||||
Server server = api.serverApi().getServer(createdServerId);
|
||||
assertEquals(server.status(), Server.Status.SHUTOFF);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testStopServer" )
|
||||
@Test(dependsOnMethods = "testStopServer")
|
||||
public void testStartServer() {
|
||||
String requestId = api.serverApi().startServer( createdServerId );
|
||||
assertNotNull( requestId );
|
||||
String requestId = api.serverApi().startServer(createdServerId);
|
||||
assertNotNull(requestId);
|
||||
|
||||
waitUntilAvailable.apply( createdServerId );
|
||||
waitUntilAvailable.apply(createdServerId);
|
||||
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
assertEquals( server.status(), Server.Status.RUNNING );
|
||||
Server server = api.serverApi().getServer(createdServerId);
|
||||
assertEquals(server.status(), Server.Status.RUNNING);
|
||||
}
|
||||
|
||||
@AfterClass( alwaysRun = true )
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void testDeleteServer() {
|
||||
if ( createdServerId != null ) {
|
||||
boolean result = api.serverApi().deleteServer( createdServerId );
|
||||
if (createdServerId != null) {
|
||||
boolean result = api.serverApi().deleteServer(createdServerId);
|
||||
|
||||
assertTrue( result, "Created test server was not deleted." );
|
||||
assertTrue(result, "Created test server was not deleted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,39 +16,45 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
|
||||
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
|
||||
import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerApiMockTest" )
|
||||
@Test(groups = "unit", testName = "ServerApiMockTest")
|
||||
public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllServers() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/servers.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/servers.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
try {
|
||||
List<Server> servers = api.getAllServers();
|
||||
assertRequestHasCommonProperties( server.takeRequest(), "<ws:getAllServers/>" );
|
||||
assertNotNull( servers );
|
||||
assertTrue( servers.size() == 2 );
|
||||
assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllServers/>");
|
||||
assertNotNull(servers);
|
||||
assertTrue(servers.size() == 2);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -58,15 +64,15 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testGetAllServersReturning404() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setResponseCode( 404 ) );
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
try {
|
||||
List<Server> servers = api.getAllServers();
|
||||
assertRequestHasCommonProperties( server.takeRequest() );
|
||||
assertTrue( servers.isEmpty() );
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertTrue(servers.isEmpty());
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -76,19 +82,19 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testGetServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:getServer><serverId>" + id + "</serverId></ws:getServer>";
|
||||
try {
|
||||
Server svr = api.getServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertNotNull( svr );
|
||||
assertEquals( svr.id(), id );
|
||||
Server svr = api.getServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(svr);
|
||||
assertEquals(svr.id(), id);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -98,16 +104,16 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testGetNonExistingServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setResponseCode( 404 ) );
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
Server srvr = api.getServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest() );
|
||||
assertNull( srvr );
|
||||
Server srvr = api.getServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertNull(srvr);
|
||||
|
||||
} finally {
|
||||
pbApi.close();
|
||||
|
@ -118,18 +124,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testStartServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-start.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-start.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:startServer><serverId>" + id + "</serverId></ws:startServer>";
|
||||
try {
|
||||
String requestId = api.startServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertEquals( requestId, "123456" );
|
||||
String requestId = api.startServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertEquals(requestId, "123456");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -139,17 +145,17 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testStartNonExistingServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setResponseCode( 500 ).setBody( payloadFromResource( "/fault-404.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
String requestId = api.startServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest() );
|
||||
fail( "Should've failed." );
|
||||
} catch ( ResourceNotFoundException ex ) {
|
||||
String requestId = api.startServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
fail("Should've failed.");
|
||||
} catch (ResourceNotFoundException ex) {
|
||||
// expected exception
|
||||
} finally {
|
||||
pbApi.close();
|
||||
|
@ -160,18 +166,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testStopServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-stop.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-stop.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:stopServer><serverId>" + id + "</serverId></ws:stopServer>";
|
||||
try {
|
||||
String requestId = api.stopServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertEquals( requestId, "123456" );
|
||||
String requestId = api.stopServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertEquals(requestId, "123456");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -181,18 +187,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testResetServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-reset.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-reset.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:resetServer><serverId>" + id + "</serverId></ws:resetServer>";
|
||||
try {
|
||||
String requestId = api.resetServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertEquals( requestId, "123456" );
|
||||
String requestId = api.resetServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertEquals(requestId, "123456");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -202,9 +208,9 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testCreateServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-create.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-create.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
|
@ -233,26 +239,26 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
+ "</ws:createServer>";
|
||||
|
||||
try {
|
||||
String serverId = api.createServer( Server.Request.creatingBuilder()
|
||||
.dataCenterId( dataCenterId )
|
||||
.name( name )
|
||||
.cores( 4 )
|
||||
.ram( 4 * 1024 )
|
||||
.bootFromImageId( imageId )
|
||||
.hasInternetAccess( Boolean.TRUE )
|
||||
.lanId( 2 )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.ZONE_1 )
|
||||
.isCpuHotPlug( Boolean.TRUE )
|
||||
.isRamHotPlug( Boolean.FALSE )
|
||||
.isNicHotPlug( Boolean.TRUE )
|
||||
.isNicHotUnPlug( Boolean.FALSE )
|
||||
.isDiscVirtioHotPlug( Boolean.TRUE )
|
||||
.isDiscVirtioHotUnPlug( Boolean.FALSE )
|
||||
.build() );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertNotNull( serverId );
|
||||
assertEquals( serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop" );
|
||||
String serverId = api.createServer(Server.Request.creatingBuilder()
|
||||
.dataCenterId(dataCenterId)
|
||||
.name(name)
|
||||
.cores(4)
|
||||
.ram(4 * 1024)
|
||||
.bootFromImageId(imageId)
|
||||
.hasInternetAccess(Boolean.TRUE)
|
||||
.lanId(2)
|
||||
.osType(OsType.LINUX)
|
||||
.availabilityZone(AvailabilityZone.ZONE_1)
|
||||
.isCpuHotPlug(Boolean.TRUE)
|
||||
.isRamHotPlug(Boolean.FALSE)
|
||||
.isNicHotPlug(Boolean.TRUE)
|
||||
.isNicHotUnPlug(Boolean.FALSE)
|
||||
.isDiscVirtioHotPlug(Boolean.TRUE)
|
||||
.isDiscVirtioHotUnPlug(Boolean.FALSE)
|
||||
.build());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(serverId);
|
||||
assertEquals(serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -262,9 +268,9 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testUpdateServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-update.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-update.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
@ -278,7 +284,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
+ "<ram>8192</ram>"
|
||||
+ "<serverName>" + newName + "</serverName>"
|
||||
+ "<bootFromStorageId>" + storageId + "</bootFromStorageId>"
|
||||
// + "<bootFromImageId>?</bootFromImageId>"
|
||||
// + "<bootFromImageId>?</bootFromImageId>"
|
||||
+ "<osType>OTHER</osType>"
|
||||
+ "<availabilityZone>AUTO</availabilityZone>"
|
||||
+ "<cpuHotPlug>false</cpuHotPlug>"
|
||||
|
@ -290,24 +296,24 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
+ "</request>"
|
||||
+ "</ws:updateServer>";
|
||||
try {
|
||||
String requestId = api.updateServer( Server.Request.updatingBuilder()
|
||||
.id( serverId )
|
||||
.name( newName )
|
||||
.cores( 8 )
|
||||
.ram( 8 * 1024 )
|
||||
.bootFromStorageId( storageId )
|
||||
.osType( OsType.OTHER )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( false )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( false )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( false )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.build() );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertNotNull( requestId );
|
||||
assertEquals( requestId, "102458" );
|
||||
String requestId = api.updateServer(Server.Request.updatingBuilder()
|
||||
.id(serverId)
|
||||
.name(newName)
|
||||
.cores(8)
|
||||
.ram(8 * 1024)
|
||||
.bootFromStorageId(storageId)
|
||||
.osType(OsType.OTHER)
|
||||
.availabilityZone(AvailabilityZone.AUTO)
|
||||
.isCpuHotPlug(false)
|
||||
.isRamHotPlug(true)
|
||||
.isNicHotPlug(false)
|
||||
.isNicHotUnPlug(true)
|
||||
.isDiscVirtioHotPlug(false)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.build());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(requestId);
|
||||
assertEquals(requestId, "102458");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
|
@ -317,22 +323,41 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
|||
@Test
|
||||
public void testDeleteServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-delete.xml" ) ) );
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-delete.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
|
||||
String content = "<ws:deleteServer><serverId>" + serverId + "</serverId></ws:deleteServer>";
|
||||
try {
|
||||
boolean result = api.deleteServer( serverId );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertTrue( result );
|
||||
boolean result = api.deleteServer(serverId);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertTrue(result);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteNonExistingServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
boolean result = api.deleteServer(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertFalse(result);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
|
||||
import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware;
|
||||
import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.util.Predicates2;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Test(groups = "live", testName = "StorageApiLiveTest", singleThreaded = true)
|
||||
public class StorageApiLiveTest extends BaseProfitBricksLiveTest {
|
||||
|
||||
private Predicate<String> waitUntilAvailable;
|
||||
private DataCenter dataCenter;
|
||||
private Server server;
|
||||
private String createdStorageId;
|
||||
|
||||
@Override
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters();
|
||||
assertFalse(dataCenters.isEmpty(), "Must atleast have 1 datacenter available for storage testing.");
|
||||
|
||||
dataCenter = Iterables.getFirst(dataCenters, null);
|
||||
if (dataCenter != null)
|
||||
dataCenter = api.dataCenterApi().getDataCenter(dataCenter.id()); // fetch individual to load more properties
|
||||
|
||||
this.waitUntilAvailable = Predicates2.retry(
|
||||
new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.STORAGE, ProvisioningState.AVAILABLE),
|
||||
6l * 60l, 2l, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = InsufficientResourcesException.class)
|
||||
public void testUberStorage() {
|
||||
api.storageApi().createStorage(
|
||||
Storage.Request.creatingBuilder()
|
||||
.dataCenterId(dataCenter)
|
||||
.name("Uber Storage")
|
||||
.size(9999999f)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStorage() {
|
||||
String storageId = api.storageApi().createStorage(
|
||||
Storage.Request.creatingBuilder()
|
||||
.dataCenterId(dataCenter)
|
||||
.name("hdd-1")
|
||||
.size(2f)
|
||||
.build());
|
||||
|
||||
assertNotNull(storageId);
|
||||
createdStorageId = storageId;
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateStorage")
|
||||
public void testGetStorage() {
|
||||
Storage storage = api.storageApi().getStorage(createdStorageId);
|
||||
|
||||
assertNotNull(storage);
|
||||
assertEquals(storage.id(), createdStorageId);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateStorage")
|
||||
public void testGetAllStorages() {
|
||||
List<Storage> storages = api.storageApi().getAllStorages();
|
||||
|
||||
assertNotNull(storages);
|
||||
assertFalse(storages.isEmpty());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateStorage")
|
||||
public void testWaitUntilAvailable() {
|
||||
boolean available = waitUntilAvailable.apply(createdStorageId);
|
||||
|
||||
assertTrue(available);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testWaitUntilAvailable")
|
||||
public void testUpdateStorage() {
|
||||
String requestId = api.storageApi().updateStorage(
|
||||
Storage.Request.updatingBuilder()
|
||||
.id(createdStorageId)
|
||||
.name("hdd-2")
|
||||
.size(5l)
|
||||
.build());
|
||||
|
||||
assertNotNull(requestId);
|
||||
waitUntilAvailable.apply(createdStorageId);
|
||||
|
||||
Storage storage = api.storageApi().getStorage(createdStorageId);
|
||||
assertEquals(storage.size(), 5f);
|
||||
assertEquals(storage.name(), "hdd-2");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdateStorage")
|
||||
public void testConnectStorage() {
|
||||
server = Iterables.getFirst(dataCenter.servers(), null);
|
||||
assertNotNull(server, "No server to attach to.");
|
||||
|
||||
String requestId = api.storageApi().connectStorageToServer(
|
||||
Storage.Request.connectingBuilder()
|
||||
.storageId(createdStorageId)
|
||||
.serverId(server.id())
|
||||
.build()
|
||||
);
|
||||
|
||||
assertNotNull(requestId);
|
||||
waitUntilAvailable.apply(createdStorageId);
|
||||
|
||||
Storage storage = api.storageApi().getStorage(createdStorageId);
|
||||
assertTrue(storage.serverIds().contains(server.id()));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testConnectStorage")
|
||||
public void testDisconnectStorage() {
|
||||
String requestId = api.storageApi()
|
||||
.disconnectStorageFromServer(createdStorageId, server.id());
|
||||
|
||||
assertNotNull(requestId);
|
||||
waitUntilAvailable.apply(createdStorageId);
|
||||
|
||||
Storage storage = api.storageApi().getStorage(createdStorageId);
|
||||
assertFalse(storage.serverIds().contains(server.id()));
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void testDeleteStorage() {
|
||||
if (createdStorageId != null) {
|
||||
boolean result = api.storageApi().deleteStorage(createdStorageId);
|
||||
|
||||
assertTrue(result, "Created test storage was not delete.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
|
||||
@Test(groups = "unit", testName = "StorageApiMockTest")
|
||||
public class StorageApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllStorages() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storages.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
try {
|
||||
List<Storage> storages = api.getAllStorages();
|
||||
assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllStorages/>");
|
||||
assertNotNull(storages);
|
||||
assertTrue(storages.size() == 2);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllStoragesReturning404() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
try {
|
||||
List<Storage> storages = api.getAllStorages();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertTrue(storages.isEmpty());
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStorage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
|
||||
|
||||
String content = "<ws:getStorage><storageId>" + id + "</storageId></ws:getStorage>";
|
||||
try {
|
||||
Storage storage = api.getStorage(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(storage);
|
||||
assertEquals(storage.id(), id);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonExistingStorage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
Storage storage = api.getStorage(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertNull(storage);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectStorageToServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-connect.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
|
||||
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:connectStorageToServer><request>"
|
||||
+ "<storageId>" + storageId + "</storageId>"
|
||||
+ "<serverId>" + serverId + "</serverId>"
|
||||
+ "<busType>VIRTIO</busType>"
|
||||
+ "<deviceNumber>2</deviceNumber>"
|
||||
+ "</request></ws:connectStorageToServer>";
|
||||
try {
|
||||
String requestId = api.connectStorageToServer(
|
||||
Storage.Request.connectingBuilder()
|
||||
.serverId(serverId)
|
||||
.storageId(storageId)
|
||||
.busType(Storage.BusType.VIRTIO)
|
||||
.deviceNumber(2)
|
||||
.build()
|
||||
);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertEquals(requestId, "16463317");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisconnectStorageFromServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-disconnect.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
|
||||
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:disconnectStorageFromServer>"
|
||||
+ "<storageId>" + storageId + "</storageId>"
|
||||
+ "<serverId>" + serverId + "</serverId>"
|
||||
+ "</ws:disconnectStorageFromServer>";
|
||||
|
||||
try {
|
||||
String requestId = api.disconnectStorageFromServer(storageId, serverId);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertEquals(requestId, "16463318");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStorage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-create.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
String imageId = "f0a59a5c-7940-11e4-8053-52540066fee9";
|
||||
|
||||
String content = "<ws:createStorage><request>"
|
||||
+ "<dataCenterId>" + dataCenterId + "</dataCenterId>"
|
||||
+ "<storageName>hdd-1</storageName>" + "<size>80</size>"
|
||||
+ "<mountImageId>" + imageId + "</mountImageId>"
|
||||
+ "<profitBricksImagePassword>qqqqqqqqq</profitBricksImagePassword>"
|
||||
+ "</request></ws:createStorage>";
|
||||
try {
|
||||
String storageId = api.createStorage(
|
||||
Storage.Request.creatingBuilder()
|
||||
.dataCenterId(dataCenterId)
|
||||
.name("hdd-1")
|
||||
.size(80f)
|
||||
.mountImageId(imageId)
|
||||
.imagePassword("qqqqqqqqq")
|
||||
.build());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(storageId);
|
||||
assertEquals(storageId, "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStorage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-update.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
|
||||
String imageId = "f4742db0-9160-11e4-9d74-52540066fee9";
|
||||
|
||||
String content = "<ws:updateStorage><request>"
|
||||
+ "<storageId>" + storageId + "</storageId>"
|
||||
+ "<size>20</size><storageName>hdd-2</storageName>"
|
||||
+ "<mountImageId>" + imageId + "</mountImageId>"
|
||||
+ "</request></ws:updateStorage>";
|
||||
try {
|
||||
String requestId = api.updateStorage(
|
||||
Storage.Request.updatingBuilder()
|
||||
.id(storageId)
|
||||
.size(20f)
|
||||
.name("hdd-2")
|
||||
.mountImageId(imageId)
|
||||
.build());
|
||||
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(requestId);
|
||||
assertEquals(requestId, "1234568");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteStorage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-delete.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
|
||||
|
||||
String content = "<ws:deleteStorage><storageId>" + storageId + "</storageId></ws:deleteStorage>";
|
||||
|
||||
try {
|
||||
boolean result = api.deleteStorage(storageId);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertTrue(result);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteNonExistingStorage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
StorageApi api = pbApi.storageApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
boolean result = api.deleteStorage(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertFalse(result);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,12 +20,16 @@ import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWeb
|
|||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.features.DataCenterApi;
|
||||
import org.jclouds.profitbricks.features.ServerApi;
|
||||
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -38,6 +42,8 @@ import com.squareup.okhttp.mockwebserver.MockWebServer;
|
|||
@Test(groups = "unit", testName = "ResponseStatusFromPayloadHttpCommandExecutorServiceTest")
|
||||
public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends BaseProfitBricksMockTest {
|
||||
|
||||
private final int MAX_RETRIES = 5;
|
||||
|
||||
@Test
|
||||
public void testNotFound() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
|
@ -95,4 +101,43 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas
|
|||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverLimitSettings() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/fault-413.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl("/"));
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
try {
|
||||
api.createServer(Server.Request.CreatePayload.create("some-datacenter-id", "node1", 99, 12800));
|
||||
fail("Request should have failed.");
|
||||
} catch (Exception ex) {
|
||||
assertTrue(ex instanceof InsufficientResourcesException, "Exception should be InsufficientResourcesException");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServiceUnderMaintenance() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
for (int i = 0; i <= MAX_RETRIES; i++) // jclouds retries 5 times
|
||||
server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/maintenance-503.html")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl("/"));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
try {
|
||||
api.clearDataCenter("some-datacenter-id");
|
||||
fail("Request should have failed.");
|
||||
} catch (Exception ex) {
|
||||
assertTrue(ex instanceof HttpResponseException, "Exception should be HttpResponseException");
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ import org.testng.annotations.Test;
|
|||
public class ProfitBricksSoapMessageEnvelopeTest {
|
||||
|
||||
private final String SOAP_PREFIX
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
private final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
|
||||
private final String endpoint = "https://api.profitbricks.com/1.3";
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ public abstract class BaseResponseHandlerTest<T> {
|
|||
|
||||
protected String payloadFromResource(String resource) {
|
||||
try {
|
||||
return toStringAndClose(getClass().getResourceAsStream(resource));
|
||||
return toStringAndClose(getClass().getResourceAsStream(resource));
|
||||
} catch (IOException e) {
|
||||
throw Throwables.propagate(e);
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,57 +20,57 @@ import org.jclouds.http.functions.ParseSax;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "RequestIdOnlyResponseHandlerTest" )
|
||||
@Test(groups = "unit", testName = "RequestIdOnlyResponseHandlerTest")
|
||||
public class RequestIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<String> createParser() {
|
||||
return factory.create( injector.getInstance( RequestIdOnlyResponseHandler.class ) );
|
||||
return factory.create(injector.getInstance(RequestIdOnlyResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromStartServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-start.xml" ) );
|
||||
String requestId = parser.parse(payloadFromResource("/server/server-start.xml"));
|
||||
|
||||
assertEquals( requestId, "123456" );
|
||||
assertEquals(requestId, "123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromStopServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-stop.xml" ) );
|
||||
String requestId = parser.parse(payloadFromResource("/server/server-stop.xml"));
|
||||
|
||||
assertEquals( requestId, "123456" );
|
||||
assertEquals(requestId, "123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromResetServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-reset.xml" ) );
|
||||
String requestId = parser.parse(payloadFromResource("/server/server-reset.xml"));
|
||||
|
||||
assertEquals( requestId, "123456" );
|
||||
assertEquals(requestId, "123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromUpdateServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-update.xml" ) );
|
||||
String requestId = parser.parse(payloadFromResource("/server/server-update.xml"));
|
||||
|
||||
assertEquals( requestId, "102458" );
|
||||
assertEquals(requestId, "102458");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromDeleteServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-delete.xml" ) );
|
||||
String requestId = parser.parse(payloadFromResource("/server/server-delete.xml"));
|
||||
|
||||
assertEquals( requestId, "102459" );
|
||||
assertEquals(requestId, "102459");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,11 +38,11 @@ public class ServiceFaultResponseHandlerTest extends BaseResponseHandlerTest<Ser
|
|||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
ServiceFault expected = ServiceFault.builder()
|
||||
.faultCode(ServiceFault.FaultCode.RESOURCE_NOT_FOUND)
|
||||
.httpCode(404)
|
||||
.message("The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id")
|
||||
.requestId(16370720)
|
||||
.build();
|
||||
.faultCode(ServiceFault.FaultCode.RESOURCE_NOT_FOUND)
|
||||
.httpCode(404)
|
||||
.message("The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id")
|
||||
.requestId(16370720)
|
||||
.build();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
|
|
@ -19,14 +19,21 @@ package org.jclouds.profitbricks.http.parser.datacenter;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@Test(groups = "unit", testName = "DataCenterInfoResponseHandlerTest")
|
||||
public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<DataCenter> {
|
||||
|
||||
|
@ -35,19 +42,57 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D
|
|||
return factory.create(injector.getInstance(DataCenterInfoResponseHandler.class));
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance(DateCodecFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetDataCenter() {
|
||||
ParseSax<DataCenter> parser = createParser();
|
||||
|
||||
DataCenter actual = parser.parse(payloadFromResource("/datacenter/datacenter.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
DataCenter expected = DataCenter.builder()
|
||||
.id("12345678-abcd-efgh-ijkl-987654321000")
|
||||
.version(10)
|
||||
.name("JClouds-DC")
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.location(Location.US_LAS)
|
||||
.build();
|
||||
assertEquals(expected, actual);
|
||||
.id("12345678-abcd-efgh-ijkl-987654321000")
|
||||
.version(10)
|
||||
.name("JClouds-DC")
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.location(Location.US_LAS)
|
||||
.servers(ImmutableList.<Server>of(
|
||||
Server.builder()
|
||||
.id("12345678-abcd-efgh-ijkl-987654321000")
|
||||
.name("jnode1")
|
||||
.cores(4)
|
||||
.ram(4096)
|
||||
.hasInternetAccess(true)
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.status(Server.Status.RUNNING)
|
||||
.creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z"))
|
||||
.osType(OsType.LINUX)
|
||||
.availabilityZone(AvailabilityZone.AUTO)
|
||||
.isCpuHotPlug(true)
|
||||
.isRamHotPlug(true)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.build()
|
||||
))
|
||||
.storages(ImmutableList.<Storage>of(
|
||||
Storage.builder()
|
||||
.id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh")
|
||||
.size(40)
|
||||
.name("jnode1-disk1")
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z"))
|
||||
.build()
|
||||
))
|
||||
.build();
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ public class DataCenterListResponseHandlerTest extends BaseResponseHandlerTest<L
|
|||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
List<DataCenter> expected = ImmutableList.<DataCenter>of(
|
||||
DataCenter.builder().id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").name("JClouds-DC").version(10).state(ProvisioningState.AVAILABLE).build(),
|
||||
DataCenter.builder().id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy").name("Random DC").version(238).state(ProvisioningState.INPROCESS).build()
|
||||
DataCenter.builder().id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").name("JClouds-DC").version(10).state(ProvisioningState.AVAILABLE).build(),
|
||||
DataCenter.builder().id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy").name("Random DC").version(238).state(ProvisioningState.INPROCESS).build()
|
||||
);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
|
|
@ -25,41 +25,41 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ImageInfoResponseHandlerTest" )
|
||||
@Test(groups = "unit", testName = "ImageInfoResponseHandlerTest")
|
||||
public class ImageInfoResponseHandlerTest extends BaseResponseHandlerTest<Image> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<Image> createParser() {
|
||||
return factory.create( injector.getInstance( ImageInfoResponseHandler.class ) );
|
||||
return factory.create(injector.getInstance(ImageInfoResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetImage() {
|
||||
ParseSax<Image> parser = createParser();
|
||||
Image actual = parser.parse( payloadFromResource( "/image/image.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
Image actual = parser.parse(payloadFromResource("/image/image.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
Image expected = Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "5ad99c9e-9166-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-14.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.US_LAS )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("5ad99c9e-9166-11e4-9d74-52540066fee9")
|
||||
.name("Ubuntu-14.04-LTS-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.US_LAS)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build();
|
||||
|
||||
assertEquals( expected, actual );
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,157 +27,157 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ImageListResponseHandlerTest" )
|
||||
@Test(groups = "unit", testName = "ImageListResponseHandlerTest")
|
||||
public class ImageListResponseHandlerTest extends BaseResponseHandlerTest<List<Image>> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<List<Image>> createParser() {
|
||||
return factory.create( injector.getInstance( ImageListResponseHandler.class ) );
|
||||
return factory.create(injector.getInstance(ImageListResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetAllImages() {
|
||||
ParseSax<List<Image>> parser = createParser();
|
||||
|
||||
List<Image> actual = parser.parse( payloadFromResource( "/image/images.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
List<Image> actual = parser.parse(payloadFromResource("/image/images.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
List<Image> expected = ImmutableList.<Image>of(
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "e4f73936-9161-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-12.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.DE_FRA )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("e4f73936-9161-11e4-9d74-52540066fee9")
|
||||
.name("Ubuntu-12.04-LTS-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.DE_FRA)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "a984a5d3-9163-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-14.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.DE_FRA )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("a984a5d3-9163-11e4-9d74-52540066fee9")
|
||||
.name("Ubuntu-14.04-LTS-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.DE_FRA)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "5f3cac96-915f-11e4-9d74-52540066fee9" )
|
||||
.name( "Debian-jessie-prerelease-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.UNRECOGNIZED )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("5f3cac96-915f-11e4-9d74-52540066fee9")
|
||||
.name("Debian-jessie-prerelease-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.UNRECOGNIZED)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "f4742db0-9160-11e4-9d74-52540066fee9" )
|
||||
.name( "Fedora-19-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.UNRECOGNIZED )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("f4742db0-9160-11e4-9d74-52540066fee9")
|
||||
.name("Fedora-19-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.UNRECOGNIZED)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "86902c18-9164-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-12.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.UNRECOGNIZED )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("86902c18-9164-11e4-9d74-52540066fee9")
|
||||
.name("Ubuntu-12.04-LTS-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.UNRECOGNIZED)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "3b48e3ff-9163-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-14.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.DE_FKB )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("3b48e3ff-9163-11e4-9d74-52540066fee9")
|
||||
.name("Ubuntu-14.04-LTS-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.DE_FKB)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "6ce17716-9164-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-12.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.US_LAS )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.isBootable(true)
|
||||
.isCpuHotPlug(true)
|
||||
.isCpuHotUnPlug(false)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.id("6ce17716-9164-11e4-9d74-52540066fee9")
|
||||
.name("Ubuntu-12.04-LTS-server-2015-01-01")
|
||||
.size(2048f)
|
||||
.type(Image.Type.HDD)
|
||||
.location(Location.US_LAS)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.osType(OsType.LINUX)
|
||||
.isPublic(true)
|
||||
.isRamHotPlug(true)
|
||||
.isRamHotUnPlug(false)
|
||||
.isWriteable(true)
|
||||
.build()
|
||||
);
|
||||
|
||||
assertEquals( expected, actual );
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,20 +21,20 @@ import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerIdOnlyResponseHandlerTest" )
|
||||
@Test(groups = "unit", testName = "ServerIdOnlyResponseHandlerTest")
|
||||
public class ServerIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<String> createParser() {
|
||||
return factory.create( injector.getInstance( ServerIdOnlyResponseHandler.class ) );
|
||||
return factory.create(injector.getInstance(ServerIdOnlyResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromCreateServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String serverId = parser.parse( payloadFromResource( "/server/server-create.xml" ) );
|
||||
String serverId = parser.parse(payloadFromResource("/server/server-create.xml"));
|
||||
|
||||
assertEquals( "qwertyui-qwer-qwer-qwer-qwertyyuiiop", serverId );
|
||||
assertEquals("qwertyui-qwer-qwer-qwer-qwertyyuiiop", serverId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import java.text.ParseException;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
|
@ -25,52 +27,51 @@ import org.jclouds.profitbricks.domain.OsType;
|
|||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerInfoResponseHandlerTest" )
|
||||
@Test(groups = "unit", testName = "ServerInfoResponseHandlerTest")
|
||||
public class ServerInfoResponseHandlerTest extends BaseResponseHandlerTest<Server> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<Server> createParser() {
|
||||
return factory.create( injector.getInstance( ServerInfoResponseHandler.class ) );
|
||||
return factory.create(injector.getInstance(ServerInfoResponseHandler.class));
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance( DateCodecFactory.class );
|
||||
return injector.getInstance(DateCodecFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetServer() throws ParseException {
|
||||
public void testParseResponseFromGetServer() {
|
||||
ParseSax<Server> parser = createParser();
|
||||
|
||||
Server actual = parser.parse( payloadFromResource( "/server/server.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
Server actual = parser.parse(payloadFromResource("/server/server.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
Server expected = Server.builder()
|
||||
.id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" )
|
||||
.name( "facebook-node" )
|
||||
.cores( 4 )
|
||||
.ram( 4096 )
|
||||
.hasInternetAccess( true )
|
||||
.state( ProvisioningState.AVAILABLE )
|
||||
.status( Server.Status.RUNNING )
|
||||
.creationTime( dateParser.toDate( "2014-12-04T07:09:23.138Z" ) )
|
||||
.lastModificationTime( dateParser.toDate( "2014-12-12T03:08:35.629Z" ) )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( true )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id("qwertyui-qwer-qwer-qwer-qwertyyuiiop")
|
||||
.name("facebook-node")
|
||||
.cores(4)
|
||||
.ram(4096)
|
||||
.hasInternetAccess(true)
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.status(Server.Status.RUNNING)
|
||||
.creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z"))
|
||||
.osType(OsType.LINUX)
|
||||
.availabilityZone(AvailabilityZone.AUTO)
|
||||
.isCpuHotPlug(true)
|
||||
.isRamHotPlug(true)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.build();
|
||||
|
||||
assertEquals( actual, expected );
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,68 +30,68 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerListResponseHandlerTest" )
|
||||
@Test(groups = "unit", testName = "ServerListResponseHandlerTest")
|
||||
public class ServerListResponseHandlerTest extends BaseResponseHandlerTest<List<Server>> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<List<Server>> createParser() {
|
||||
return factory.create( injector.getInstance( ServerListResponseHandler.class ) );
|
||||
return factory.create(injector.getInstance(ServerListResponseHandler.class));
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance( DateCodecFactory.class );
|
||||
return injector.getInstance(DateCodecFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetAllServers() {
|
||||
ParseSax<List<Server>> parser = createParser();
|
||||
|
||||
List<Server> actual = parser.parse( payloadFromResource( "/server/servers.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
List<Server> actual = parser.parse(payloadFromResource("/server/servers.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
List<Server> expected = ImmutableList.<Server>of(
|
||||
Server.builder()
|
||||
.id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" )
|
||||
.name( "facebook-node" )
|
||||
.cores( 4 )
|
||||
.ram( 4096 )
|
||||
.hasInternetAccess( true )
|
||||
.state( ProvisioningState.AVAILABLE )
|
||||
.status( Server.Status.RUNNING )
|
||||
.creationTime( dateParser.toDate( "2014-12-04T07:09:23.138Z" ) )
|
||||
.lastModificationTime( dateParser.toDate( "2014-12-12T03:08:35.629Z" ) )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( true )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id("qwertyui-qwer-qwer-qwer-qwertyyuiiop")
|
||||
.name("facebook-node")
|
||||
.cores(4)
|
||||
.ram(4096)
|
||||
.hasInternetAccess(true)
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.status(Server.Status.RUNNING)
|
||||
.creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z"))
|
||||
.osType(OsType.LINUX)
|
||||
.availabilityZone(AvailabilityZone.AUTO)
|
||||
.isCpuHotPlug(true)
|
||||
.isRamHotPlug(true)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.build(),
|
||||
Server.builder()
|
||||
.id( "asdfghjk-asdf-asdf-asdf-asdfghjklkjl" )
|
||||
.name( "google-node" )
|
||||
.cores( 1 )
|
||||
.ram( 1024 )
|
||||
.hasInternetAccess( false )
|
||||
.state( ProvisioningState.AVAILABLE )
|
||||
.status( Server.Status.RUNNING )
|
||||
.creationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) )
|
||||
.lastModificationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( true )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id("asdfghjk-asdf-asdf-asdf-asdfghjklkjl")
|
||||
.name("google-node")
|
||||
.cores(1)
|
||||
.ram(1024)
|
||||
.hasInternetAccess(false)
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.status(Server.Status.RUNNING)
|
||||
.creationTime(dateParser.toDate("2014-11-12T07:01:00.441Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-11-12T07:01:00.441Z"))
|
||||
.osType(OsType.LINUX)
|
||||
.availabilityZone(AvailabilityZone.AUTO)
|
||||
.isCpuHotPlug(true)
|
||||
.isRamHotPlug(true)
|
||||
.isNicHotPlug(true)
|
||||
.isNicHotUnPlug(true)
|
||||
.isDiscVirtioHotPlug(true)
|
||||
.isDiscVirtioHotUnPlug(true)
|
||||
.build()
|
||||
);
|
||||
|
||||
assertEquals( actual, expected );
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,70 +40,70 @@ public class GetProvisioningStateResponseHandlerTest extends BaseResponseHandler
|
|||
ParseSax<ProvisioningState> parser = createParser();
|
||||
|
||||
for (Map.Entry<ProvisioningState, String> pair : sampleResponses.entrySet()) {
|
||||
ProvisioningState actual = parser.parse(pair.getValue());
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
ProvisioningState actual = parser.parse(pair.getValue());
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
assertEquals(pair.getKey(), actual);
|
||||
assertEquals(pair.getKey(), actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Map<ProvisioningState, String> sampleResponses = new LinkedHashMap<ProvisioningState, String>() {
|
||||
{
|
||||
put(ProvisioningState.INACTIVE,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>INACTIVE</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.INPROCESS,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>INPROCESS</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.AVAILABLE,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>AVAILABLE</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.DELETED,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>DELETED</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.ERROR,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>ERROR</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.UNRECOGNIZED,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>MEH</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.INACTIVE,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>INACTIVE</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.INPROCESS,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>INPROCESS</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.AVAILABLE,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>AVAILABLE</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.DELETED,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>DELETED</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.ERROR,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>ERROR</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
put(ProvisioningState.UNRECOGNIZED,
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">\n"
|
||||
+ " <soapenv:Header/>\n"
|
||||
+ " <soapenv:Body>\n"
|
||||
+ " <ws:getDataCenterStateResponse>\n"
|
||||
+ " <return>MEH</return>\n"
|
||||
+ " </ws:getDataCenterStateResponse>\n"
|
||||
+ " </soapenv:Body>\n"
|
||||
+ "</soapenv:Envelope>");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "unit", testName = "StorageIdOnlyResponseHandlerTest")
|
||||
public class StorageIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<String> createParser() {
|
||||
return factory.create(injector.getInstance(StorageIdOnlyResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromCreateStorage() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String storageId = parser.parse(payloadFromResource("/storage/storage-create.xml"));
|
||||
|
||||
assertEquals("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh", storageId);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@Test(groups = "unit", testName = "StorageInfoResponseHandlerTest")
|
||||
public class StorageInfoResponseHandlerTest extends BaseResponseHandlerTest<Storage> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<Storage> createParser() {
|
||||
return factory.create(injector.getInstance(StorageInfoResponseHandler.class));
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance(DateCodecFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetStorage() {
|
||||
ParseSax<Storage> parser = createParser();
|
||||
|
||||
Storage actual = parser.parse(payloadFromResource("/storage/storage.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
Storage expected = Storage.builder()
|
||||
.id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh")
|
||||
.size(40)
|
||||
.name("hdd-1")
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.serverIds(ImmutableList.<String>of("qwertyui-qwer-qwer-qwer-qwertyyuiiop"))
|
||||
.creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z"))
|
||||
.build();
|
||||
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.storage;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Storage;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "unit", testName = "StorageListResponseHandlerTest")
|
||||
public class StorageListResponseHandlerTest extends BaseResponseHandlerTest<List<Storage>> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<List<Storage>> createParser() {
|
||||
return factory.create(injector.getInstance(StorageListResponseHandler.class));
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance(DateCodecFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetAllStorages() {
|
||||
ParseSax<List<Storage>> parser = createParser();
|
||||
|
||||
List<Storage> actual = parser.parse(payloadFromResource("/storage/storages.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
List<Storage> expected = ImmutableList.<Storage>of(
|
||||
Storage.builder()
|
||||
.id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh")
|
||||
.size(40f)
|
||||
.name("hdd-1")
|
||||
.state(ProvisioningState.AVAILABLE)
|
||||
.serverIds(ImmutableList.<String>of("qwertyui-qwer-qwer-qwer-qwertyyuiiop"))
|
||||
.creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z"))
|
||||
.build(),
|
||||
Storage.builder()
|
||||
.id("asfasfle-f23n-cu89-klfr-njkdsvwllkfa")
|
||||
.size(100f)
|
||||
.name("hdd-2")
|
||||
.state(ProvisioningState.INPROCESS)
|
||||
.serverIds(ImmutableList.<String>of("asdfghjk-asdf-asdf-asdf-asdfghjklkjl"))
|
||||
.creationTime(dateParser.toDate("2014-11-04T07:09:23.138Z"))
|
||||
.lastModificationTime(dateParser.toDate("2014-11-12T03:14:48.316Z"))
|
||||
.build()
|
||||
);
|
||||
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
}
|
|
@ -46,11 +46,11 @@ public class BaseProfitBricksMockTest {
|
|||
protected static final String authHeader = BasicAuthentication.basic("username", "password");
|
||||
protected static final String provider = "profitbricks";
|
||||
protected static final String rootUrl = "/1.3";
|
||||
|
||||
|
||||
private static final String SOAP_PREFIX
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
|
||||
private static final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class BaseProfitBricksMockTest {
|
|||
server.play();
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
public byte[] payloadFromResource(String resource) {
|
||||
try {
|
||||
return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8);
|
||||
|
@ -85,9 +85,9 @@ public class BaseProfitBricksMockTest {
|
|||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static String payloadSoapWithBody(String body){
|
||||
return SOAP_PREFIX.concat( body ).concat( SOAP_SUFFIX );
|
||||
|
||||
protected static String payloadSoapWithBody(String body) {
|
||||
return SOAP_PREFIX.concat(body).concat(SOAP_SUFFIX);
|
||||
}
|
||||
|
||||
protected static void assertRequestHasCommonProperties(final RecordedRequest request) {
|
||||
|
@ -96,9 +96,9 @@ public class BaseProfitBricksMockTest {
|
|||
assertEquals(request.getHeader(HttpHeaders.AUTHORIZATION), authHeader);
|
||||
assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.TEXT_XML);
|
||||
}
|
||||
|
||||
protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content ){
|
||||
assertEquals( new String( request.getBody() ), payloadSoapWithBody( content ) );
|
||||
assertRequestHasCommonProperties( request );
|
||||
|
||||
protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content) {
|
||||
assertEquals(new String(request.getBody()), payloadSoapWithBody(content));
|
||||
assertRequestHasCommonProperties(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<serverId>12345678-abcd-efgh-ijkl-987654321000</serverId>
|
||||
<ips>202.94.38.12</ips>
|
||||
<macAddress>02:01:09:cd:f0:b0</macAddress>
|
||||
<firewall>`
|
||||
<firewall>
|
||||
<active>false</active>
|
||||
<firewallId>llllllll-kkkk-jjjj-hhhh-gggggggggggg</firewallId>
|
||||
<firewallId>62383ec1-38c8-486b-8fa2-a3bb0a5edd97</firewallId>
|
||||
|
|
|
@ -14,4 +14,4 @@
|
|||
</detail>
|
||||
</S:Fault>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
|
||||
<faultcode>S:Server</faultcode>
|
||||
<faultstring>New request exceeds the current capacity settings of this user contract. Please refer to Request Id : 16503940. [VDC-5-1020] Server has 12,800 MiB configured RAM. Your personal limit is 10,240 MiB per server.</faultstring>
|
||||
<detail>
|
||||
<ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<faultCode>OVER_LIMIT_SETTING</faultCode>
|
||||
<httpCode>413</httpCode>
|
||||
<message>New request exceeds the current capacity settings of this user contract. Please refer to Request Id : 16503940. [VDC-5-1020] Server has 12,800 MiB configured RAM. Your personal limit is 10,240 MiB per server.</message>
|
||||
<requestId>16503940</requestId>
|
||||
</ns2:ProfitbricksServiceFault>
|
||||
</detail>
|
||||
</S:Fault>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,67 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta lang="en" http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>Profitbricks | Maintenance</title>
|
||||
<link rel="stylesheet" type="text/css" href="css/style.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/content.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/recent_additions.css" />
|
||||
<link rel="shortcut icon" href="https://my.profitbricks.com/errorpages/favicon.ico" type="image/x-icon" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="head1 h_bg"></div>
|
||||
<div class="head2 h_bg"></div>
|
||||
<div class="head3 h_bg"></div>
|
||||
|
||||
<div id="wrapper">
|
||||
<div class="wrapper_inner">
|
||||
|
||||
<div id="header">
|
||||
<a id="logo" href="#"><img alt="Profitbricks" src="img/logo.png" /></a>
|
||||
</div>
|
||||
|
||||
<div id="main">
|
||||
<div id="right" style="min-height: 550px;">
|
||||
<div class="article msg">
|
||||
<h1>Maintenance</h1>
|
||||
<img width="49" height="49" title="" alt="message error" src="Profitbricks%20%7C%20Maintenance_files/msg_error.png" class="msg_sign" style="margin: 10px;" />
|
||||
<div class="container" style="margin:20px 80px !important;">
|
||||
<div class="bigmargin">
|
||||
<h2>Dear ProfitBricks users,</h2>
|
||||
<p>actually we are carrying out maintenance work right now.</p>
|
||||
<p>For urgent matters please contact:<br /><a href="mailto:support@profitbricks.com">support@profitbricks.com</a>.</p>
|
||||
<br />
|
||||
<p>We ask for your understanding and your patience.</p>
|
||||
<p>Your ProfitBricks Team</p>
|
||||
</div>
|
||||
|
||||
<div class="bigmargin">
|
||||
<h2>Sehr geehrte(r) ProfitBricks Nutzerin/Nutzer,</h2>
|
||||
<p>zur Zeit führen wir Wartungsarbeiten durch.</p>
|
||||
<p>Bei dringenden Angelegenheiten wenden Sie sich bitte an:<br />
|
||||
<a href="mailto:support@profitbricks.com">support@profitbricks.com</a>
|
||||
</p>
|
||||
<br />
|
||||
<p>Wir bitten Sie um Ihr Verständnis und um etwas Geduld.</p>
|
||||
<p>Ihr ProfitBricks Team</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
<div class="bottom">
|
||||
<div class="inner">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getServerResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>16577212</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>22</dataCenterVersion>
|
||||
<serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>
|
||||
<cores>1</cores>
|
||||
<ram>512</ram>
|
||||
<internetAccess>false</internetAccess>
|
||||
<provisioningState>INPROCESS</provisioningState>
|
||||
<virtualMachineState>NOSTATE</virtualMachineState>
|
||||
<creationTime>2015-01-29T00:37:49.096Z</creationTime>
|
||||
<lastModificationTime>2015-01-29T00:37:49.096Z</lastModificationTime>
|
||||
<osType>UNKNOWN</osType>
|
||||
<availabilityZone>AUTO</availabilityZone>
|
||||
<cpuHotPlug>false</cpuHotPlug>
|
||||
<ramHotPlug>false</ramHotPlug>
|
||||
<nicHotPlug>false</nicHotPlug>
|
||||
<nicHotUnPlug>false</nicHotUnPlug>
|
||||
<discVirtioHotPlug>false</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>false</discVirtioHotUnPlug>
|
||||
</return>
|
||||
</ns2:getServerResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:connectStorageToServerResponse>
|
||||
<return>
|
||||
<requestId>16463317</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>49</dataCenterVersion>
|
||||
</return>
|
||||
</ws:connectStorageToServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:createStorageReturn>
|
||||
<return>
|
||||
<requestId>1234567</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>45</dataCenterVersion>
|
||||
<storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>
|
||||
</return>
|
||||
</ws:createStorageReturn>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:deleteStorageResponse>
|
||||
<return>
|
||||
<requestId>12345679</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>47</dataCenterVersion>
|
||||
</return>
|
||||
</ws:deleteStorageResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:disconnectStorageFromServerResponse>
|
||||
<return>
|
||||
<requestId>16463318</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>50</dataCenterVersion>
|
||||
</return>
|
||||
</ws:disconnectStorageFromServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getStorageResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>16463316</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>49</dataCenterVersion>
|
||||
<storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>
|
||||
<size>40</size>
|
||||
<storageName>hdd-1</storageName>
|
||||
<mountImage>
|
||||
<imageId>f0a59a5c-7940-11e4-8053-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-14.04-LTS-server-2014-12-01</imageName>
|
||||
</mountImage>
|
||||
<serverIds>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverIds>
|
||||
<provisioningState>INPROCESS</provisioningState>
|
||||
<creationTime>2014-12-04T07:09:23.138Z</creationTime>
|
||||
<lastModificationTime>2014-12-12T03:14:48.316Z</lastModificationTime>
|
||||
</return>
|
||||
</ns2:getStorageResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:updateStorageResponse>
|
||||
<return>
|
||||
<requestId>1234568</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>46</dataCenterVersion>
|
||||
</return>
|
||||
</ws:updateStorageResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getStorageResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>16463316</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>49</dataCenterVersion>
|
||||
<storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>
|
||||
<size>40</size>
|
||||
<storageName>hdd-1</storageName>
|
||||
<mountImage>
|
||||
<imageId>f0a59a5c-7940-11e4-8053-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-14.04-LTS-server-2014-12-01</imageName>
|
||||
</mountImage>
|
||||
<serverIds>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverIds>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
<creationTime>2014-12-04T07:09:23.138Z</creationTime>
|
||||
<lastModificationTime>2014-12-12T03:14:48.316Z</lastModificationTime>
|
||||
</return>
|
||||
</ns2:getStorageResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getAllStoragesResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>49</dataCenterVersion>
|
||||
<storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>
|
||||
<size>40</size>
|
||||
<storageName>hdd-1</storageName>
|
||||
<mountImage>
|
||||
<imageId>f0a59a5c-7940-11e4-8053-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-14.04-LTS-server-2014-12-01</imageName>
|
||||
</mountImage>
|
||||
<serverIds>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverIds>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
<creationTime>2014-12-04T07:09:23.138Z</creationTime>
|
||||
<lastModificationTime>2014-12-12T03:14:48.316Z</lastModificationTime>
|
||||
</return>
|
||||
<return>
|
||||
<dataCenterId>qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy</dataCenterId>
|
||||
<dataCenterVersion>238</dataCenterVersion>
|
||||
<storageId>asfasfle-f23n-cu89-klfr-njkdsvwllkfa</storageId>
|
||||
<size>100</size>
|
||||
<storageName>hdd-2</storageName>
|
||||
<mountImage>
|
||||
<imageId>f4742db0-9160-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Fedora-19-server-2015-01-01</imageName>
|
||||
</mountImage>
|
||||
<serverIds>asdfghjk-asdf-asdf-asdf-asdfghjklkjl</serverIds>
|
||||
<provisioningState>INPROCESS</provisioningState>
|
||||
<creationTime>2014-11-04T07:09:23.138Z</creationTime>
|
||||
<lastModificationTime>2014-11-12T03:14:48.316Z</lastModificationTime>
|
||||
</return>
|
||||
</ns2:getAllStoragesResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
Loading…
Reference in New Issue