mirror of https://github.com/apache/jclouds.git
Merge remote-tracking branch 'jclouds-labs-profitbricks-local/promote-profitbricks-moved' into promoted-profitbricks
This commit is contained in:
commit
1af52159c9
|
@ -0,0 +1,61 @@
|
||||||
|
# jclouds ProfitBricks
|
||||||
|
|
||||||
|
## Terms
|
||||||
|
Like any cloud provider, ProfitBricks has its own set of terms in cloud computing. To abstract this into jclouds' Compute interface, these terms were associated:
|
||||||
|
|
||||||
|
- Node - composite instance of `Server` and `Storage`
|
||||||
|
- Image - both *user-uploaded* and *provided* `Images`; and `Snapshots`
|
||||||
|
- Location - `DataCenters` and `Region` (Las Vegas, Frankfurt, etc.)
|
||||||
|
- Hardware - number of cores, RAM size and storage size
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Assuming that there's **atleast one** datacenter existing in your account, the provider needs only an *identity* (your ProfitBricks email), and *credentials* (password) to provision a `Node`, by using a ProfitBricks-provided ubuntu-12.04 image as a template.
|
||||||
|
|
||||||
|
```java
|
||||||
|
ComputeService compute = ContextBuilder.newBuilder( "profitbricks" )
|
||||||
|
.credentials( "profitbricks email", "password" )
|
||||||
|
.buildView( ComputeServiceContext.class )
|
||||||
|
.getComputeService();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
This works well; however, we won't be able to use jclouds' ability to execute *scripts* on a remote node. This is because, ProfitBricks' default images require users to change passwords upon first log in.
|
||||||
|
|
||||||
|
To enable jclouds to execute script, we need to use a custom image. The easiest way to do this is via ProfitBricks snapshot:
|
||||||
|
|
||||||
|
- Go to your [DCD](https://my.profitbricks.com/dashboard/).
|
||||||
|
- Provision a server + storage, and connect it to the internet. Upon success, you will receive an email containing the credentials needed to login to your server.
|
||||||
|
- Login to your server, and change the password, as requested.
|
||||||
|
|
||||||
|
```
|
||||||
|
~ ssh root@<remote-ip>
|
||||||
|
...
|
||||||
|
Changing password for root.
|
||||||
|
(current) UNIX password:
|
||||||
|
Enter new UNIX password:
|
||||||
|
Retype new UNIX password:
|
||||||
|
~ root@ubuntu:~# exit
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- Go back to the DCD, and *make a snapshot* of the storage. Put a descriptive name.
|
||||||
|
- Configure jclouds to use this *snapshot*.
|
||||||
|
|
||||||
|
```java
|
||||||
|
Template template = compute.templateBuilder()
|
||||||
|
.imageNameMatches( "<ideally-unique-snapshot-name>" )
|
||||||
|
.options( compute.templateOptions()
|
||||||
|
.overrideLoginUser( "root" ) // unless you changed the user
|
||||||
|
.overrideLoginPassword( "<changed-password>" ))
|
||||||
|
// more options, as you need
|
||||||
|
.build();
|
||||||
|
|
||||||
|
compute.createNodesInGroup( "cluster1", 1, template );
|
||||||
|
```
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
- There's no direct way of specifying arbitrary number of cores, RAM size, and storage size via the compute interface, at least until after [JCLOUDS-482](https://issues.apache.org/jira/browse/JCLOUDS-482) is resolved. The adapter uses a predefined list hardware profiles instead.
|
||||||
|
|
||||||
|
> Take note that these features are still accessible by *unwraping* the ProfitBricks API, but this'll reduce portability of your code. See [Concepts](https://jclouds.apache.org/start/concepts/).
|
|
@ -0,0 +1,151 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.apache.jclouds.labs</groupId>
|
||||||
|
<artifactId>jclouds-labs</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<!-- TODO: when out of labs, switch to org.jclouds.api -->
|
||||||
|
<artifactId>profitbricks</artifactId>
|
||||||
|
<name>jclouds ProfitBricks api</name>
|
||||||
|
<description>jclouds components to access an implementation of ProfitBricks</description>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<test.profitbricks.endpoint>https://api.profitbricks.com/1.3</test.profitbricks.endpoint>
|
||||||
|
<test.profitbricks.identity>FIXME</test.profitbricks.identity>
|
||||||
|
<test.profitbricks.credential>FIXME</test.profitbricks.credential>
|
||||||
|
<test.profitbricks.api-version>1.3</test.profitbricks.api-version>
|
||||||
|
<jclouds.osgi.export>org.jclouds.profitbricks*;version="${project.version}"</jclouds.osgi.export>
|
||||||
|
<jclouds.osgi.import>
|
||||||
|
org.jclouds.labs*;version="${project.version}",
|
||||||
|
org.jclouds*;version="${jclouds.version}",
|
||||||
|
*
|
||||||
|
</jclouds.osgi.import>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-core</artifactId>
|
||||||
|
<version>${jclouds.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-compute</artifactId>
|
||||||
|
<version>${jclouds.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.auto.service</groupId>
|
||||||
|
<artifactId>auto-service</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.auto.value</groupId>
|
||||||
|
<artifactId>auto-value</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-core</artifactId>
|
||||||
|
<version>${jclouds.version}</version>
|
||||||
|
<type>test-jar</type>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-compute</artifactId>
|
||||||
|
<version>${jclouds.version}</version>
|
||||||
|
<type>test-jar</type>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jclouds.driver</groupId>
|
||||||
|
<artifactId>jclouds-sshj</artifactId>
|
||||||
|
<version>${jclouds.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp</groupId>
|
||||||
|
<artifactId>mockwebserver</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<!-- Already provided by jclouds-sshj -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jclouds.driver</groupId>
|
||||||
|
<artifactId>jclouds-slf4j</artifactId>
|
||||||
|
<version>${jclouds.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>live</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>integration</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<threadCount>1</threadCount>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<test.profitbricks.endpoint>${test.profitbricks.endpoint}</test.profitbricks.endpoint>
|
||||||
|
<test.profitbricks.identity>${test.profitbricks.identity}</test.profitbricks.identity>
|
||||||
|
<test.profitbricks.credential>${test.profitbricks.credential}</test.profitbricks.credential>
|
||||||
|
<test.profitbricks.api-version>${test.profitbricks.api-version}</test.profitbricks.api-version>
|
||||||
|
<test.profitbricks.template>${test.profitbricks.template}</test.profitbricks.template>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import org.jclouds.profitbricks.features.DataCenterApi;
|
||||||
|
import org.jclouds.profitbricks.features.DrivesApi;
|
||||||
|
import org.jclouds.profitbricks.features.FirewallApi;
|
||||||
|
import org.jclouds.profitbricks.features.ImageApi;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.features.IpBlockApi;
|
||||||
|
import org.jclouds.profitbricks.features.LoadBalancerApi;
|
||||||
|
import org.jclouds.profitbricks.features.NicApi;
|
||||||
|
import org.jclouds.profitbricks.features.ServerApi;
|
||||||
|
import org.jclouds.profitbricks.features.SnapshotApi;
|
||||||
|
import org.jclouds.profitbricks.features.StorageApi;
|
||||||
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
|
public interface ProfitBricksApi extends Closeable {
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
DataCenterApi dataCenterApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
ImageApi imageApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
ServerApi serverApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
StorageApi storageApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
NicApi nicApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
FirewallApi firewallApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
SnapshotApi snapshotApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
IpBlockApi ipBlockApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
DrivesApi drivesApi();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
LoadBalancerApi loadBalancerApi();
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.compute.config.ProfitBricksComputeServiceContextModule;
|
||||||
|
import org.jclouds.profitbricks.config.ProfitBricksHttpApiModule;
|
||||||
|
import org.jclouds.apis.ApiMetadata;
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.profitbricks.config.ProfitBricksHttpApiModule.ProfitBricksHttpCommandExecutorServiceModule;
|
||||||
|
import org.jclouds.rest.internal.BaseHttpApiMetadata;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of {@link ApiMetadata} for ProfitBricks API.
|
||||||
|
*/
|
||||||
|
public class ProfitBricksApiMetadata extends BaseHttpApiMetadata<ProfitBricksApi> {
|
||||||
|
|
||||||
|
public ProfitBricksApiMetadata() {
|
||||||
|
this(new Builder());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromApiMetadata(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProfitBricksApiMetadata(Builder builder) {
|
||||||
|
super(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Properties defaultProperties() {
|
||||||
|
Properties properties = BaseHttpApiMetadata.defaultProperties();
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
ProfitBricksComputeServiceContextModule.class
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfitBricksApiMetadata build() {
|
||||||
|
return new ProfitBricksApiMetadata(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Builder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES;
|
||||||
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
|
||||||
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||||
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE;
|
||||||
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONES;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_INITIAL_PERIOD;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_MAX_PERIOD;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.TIMEOUT_DATACENTER_AVAILABLE;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.providers.ProviderMetadata;
|
||||||
|
import org.jclouds.providers.internal.BaseProviderMetadata;
|
||||||
|
|
||||||
|
import com.google.auto.service.AutoService;
|
||||||
|
|
||||||
|
@AutoService(ProviderMetadata.class)
|
||||||
|
public class ProfitBricksProviderMetadata extends BaseProviderMetadata {
|
||||||
|
|
||||||
|
public ProfitBricksProviderMetadata(Builder builder) {
|
||||||
|
super(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProfitBricksProviderMetadata() {
|
||||||
|
super(builder());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return builder().fromProviderMetadata(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Properties defaultProperties() {
|
||||||
|
Properties properties = ProfitBricksApiMetadata.defaultProperties();
|
||||||
|
|
||||||
|
properties.setProperty(PROPERTY_REGIONS, "de,us");
|
||||||
|
properties.setProperty(PROPERTY_REGION + ".de.zones", "de/fkb,de/fra");
|
||||||
|
properties.setProperty(PROPERTY_REGION + ".us.zones", "us/las,us/lasdev");
|
||||||
|
properties.setProperty(PROPERTY_ZONES, "de/fkb,de/fra,us/las,us/lasdev");
|
||||||
|
properties.setProperty(PROPERTY_ZONE + ".de/fkb." + ISO3166_CODES, "DE-BW");
|
||||||
|
properties.setProperty(PROPERTY_ZONE + ".de/fra." + ISO3166_CODES, "DE-HE");
|
||||||
|
properties.setProperty(PROPERTY_ZONE + ".us/las." + ISO3166_CODES, "US-NV");
|
||||||
|
properties.setProperty(PROPERTY_ZONE + ".us/lasdebv." + ISO3166_CODES, "US-NV");
|
||||||
|
|
||||||
|
properties.put(TIMEOUT_DATACENTER_AVAILABLE, 30L * 60L); // 30 minutes
|
||||||
|
properties.put(POLL_INITIAL_PERIOD, 5L);
|
||||||
|
properties.put(POLL_MAX_PERIOD, 60L);
|
||||||
|
|
||||||
|
properties.put("jclouds.ssh.max-retries", "7");
|
||||||
|
properties.put("jclouds.ssh.retry-auth", "true");
|
||||||
|
|
||||||
|
properties.put(PROPERTY_SO_TIMEOUT, 10 * 60 * 1000);
|
||||||
|
|
||||||
|
// Node might still not be available even after DataCenter is done provisioning
|
||||||
|
// Use 5-minute timeout by default
|
||||||
|
properties.put(TIMEOUT_NODE_RUNNING, 5 * 60 * 1000);
|
||||||
|
properties.put(TIMEOUT_NODE_SUSPENDED, 5 * 60 * 1000);
|
||||||
|
properties.put(TIMEOUT_NODE_TERMINATED, 5 * 60 * 1000);
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
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/"))
|
||||||
|
.iso3166Codes("DE-BW", "DE-HE", "US-NV")
|
||||||
|
.linkedServices("profitbricks")
|
||||||
|
.apiMetadata(new ProfitBricksApiMetadata())
|
||||||
|
.defaultProperties(ProfitBricksProviderMetadata.defaultProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfitBricksProviderMetadata build() {
|
||||||
|
return new ProfitBricksProviderMetadata(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder fromProviderMetadata(ProviderMetadata in) {
|
||||||
|
super.fromProviderMetadata(in);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.MapBinder;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
import org.jclouds.io.MutableContentMetadata;
|
||||||
|
import org.jclouds.io.payloads.BaseMutableContentMetadata;
|
||||||
|
|
||||||
|
public abstract class BaseProfitBricksRequestBinder<T> implements MapBinder {
|
||||||
|
|
||||||
|
protected final String paramName;
|
||||||
|
|
||||||
|
protected BaseProfitBricksRequestBinder(String paramName) {
|
||||||
|
this.paramName = checkNotNull(paramName, "Initialize 'paramName' in constructor");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||||
|
checkNotNull(request, "request");
|
||||||
|
|
||||||
|
Object obj = checkNotNull(postParams.get(paramName), "Param '%s' cannot be null.", paramName);
|
||||||
|
T payload = (T) obj;
|
||||||
|
|
||||||
|
return createRequest(request, createPayload(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String createPayload(T payload);
|
||||||
|
|
||||||
|
protected static String formatIfNotEmpty(String pattern, Object param) {
|
||||||
|
return Strings.isNullOrEmpty(nullableToString(param)) ? "" : String.format(pattern, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String nullableToString(Object object) {
|
||||||
|
return object == null ? "" : object.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
|
||||||
|
MutableContentMetadata metadata = new BaseMutableContentMetadata();
|
||||||
|
metadata.setContentType(MediaType.TEXT_XML);
|
||||||
|
metadata.setContentLength(Long.valueOf(payload.getBytes().length));
|
||||||
|
|
||||||
|
fromRequest.setPayload(payload);
|
||||||
|
fromRequest.getPayload().setContentMetadata(metadata);
|
||||||
|
return fromRequest;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.datacenter;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
|
||||||
|
public class CreateDataCenterRequestBinder extends BaseProfitBricksRequestBinder<DataCenter.Request.CreatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
CreateDataCenterRequestBinder() {
|
||||||
|
super("dataCenter");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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().getId()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:createDataCenter>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.datacenter;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
|
||||||
|
public class UpdateDataCenterRequestBinder extends BaseProfitBricksRequestBinder<DataCenter.Request.UpdatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
UpdateDataCenterRequestBinder() {
|
||||||
|
super("dataCenter");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(DataCenter.Request.UpdatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:updateDataCenter>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<dataCenterId>%s</dataCenterId>", payload.id()))
|
||||||
|
.append(format("<dataCenterName>%s</dataCenterName>", payload.name()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:updateDataCenter>");
|
||||||
|
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.drive;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Drive;
|
||||||
|
|
||||||
|
public class AddRomDriveToServerRequestBinder extends BaseProfitBricksRequestBinder<Drive.Request.AddRomDriveToServerPayload> {
|
||||||
|
|
||||||
|
private final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
AddRomDriveToServerRequestBinder() {
|
||||||
|
super("payload");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Drive.Request.AddRomDriveToServerPayload payload) {
|
||||||
|
requestBuilder.append("<ws:addRomDriveToServer>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<imageId>%s</imageId>", payload.imageId()))
|
||||||
|
.append(format("<serverId>%s</serverId>", payload.serverId()))
|
||||||
|
.append(formatIfNotEmpty("<deviceNumber>%s</deviceNumber>", payload.deviceNumber()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:addRomDriveToServer>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,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.firewall;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class AddFirewallRuleToNicRequestBinder extends BaseProfitBricksRequestBinder<Firewall.Request.AddRulePayload> {
|
||||||
|
|
||||||
|
private final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
AddFirewallRuleToNicRequestBinder() {
|
||||||
|
super("firewall");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Firewall.Request.AddRulePayload payload) {
|
||||||
|
requestBuilder.append("<ws:addFirewallRulesToNic>")
|
||||||
|
.append(format("<nicId>%s</nicId>", payload.nicId()));
|
||||||
|
for (Firewall.Rule rule : payload.rules())
|
||||||
|
requestBuilder
|
||||||
|
.append("<request>")
|
||||||
|
.append(formatIfNotEmpty("<icmpCode>%s</icmpCode>", rule.icmpCode()))
|
||||||
|
.append(formatIfNotEmpty("<icmpType>%s</icmpType>", rule.icmpType()))
|
||||||
|
.append(formatIfNotEmpty("<name>%s</name>", rule.name()))
|
||||||
|
.append(formatIfNotEmpty("<portRangeEnd>%s</portRangeEnd>", rule.portRangeEnd()))
|
||||||
|
.append(formatIfNotEmpty("<portRangeStart>%s</portRangeStart>", rule.portRangeStart()))
|
||||||
|
.append(formatIfNotEmpty("<protocol>%s</protocol>", rule.protocol()))
|
||||||
|
.append(formatIfNotEmpty("<sourceIp>%s</sourceIp>", rule.sourceIp()))
|
||||||
|
.append(formatIfNotEmpty("<sourceMac>%s</sourceMac>", rule.sourceMac()))
|
||||||
|
.append(formatIfNotEmpty("<targetIp>%s</targetIp>", rule.targetIp()))
|
||||||
|
.append("</request>");
|
||||||
|
requestBuilder.append("</ws:addFirewallRulesToNic>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* 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.firewall;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
public abstract class FirewallBinder extends BaseProfitBricksRequestBinder<List<String>> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
FirewallBinder() {
|
||||||
|
super("ids");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void bindListWithTag(List<String> ids, String tag) {
|
||||||
|
if (ids == null || ids.isEmpty() || Strings.isNullOrEmpty(tag))
|
||||||
|
return;
|
||||||
|
for (String id : ids)
|
||||||
|
requestBuilder.append(format("<%s>%s</%s>", tag, id, tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ActivateFirewallRequestBinder extends FirewallBinder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(List<String> payload) {
|
||||||
|
requestBuilder.append("<ws:activateFirewalls>");
|
||||||
|
bindListWithTag(payload, "firewallIds");
|
||||||
|
requestBuilder.append("</ws:activateFirewalls>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DeactivateFirewallRequestBinder extends FirewallBinder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(List<String> payload) {
|
||||||
|
requestBuilder.append("<ws:deactivateFirewalls>");
|
||||||
|
bindListWithTag(payload, "firewallIds");
|
||||||
|
requestBuilder.append("</ws:deactivateFirewalls>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DeleteFirewallRequestBinder extends FirewallBinder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(List<String> payload) {
|
||||||
|
requestBuilder.append("<ws:deleteFirewalls>");
|
||||||
|
bindListWithTag(payload, "firewallIds");
|
||||||
|
requestBuilder.append("</ws:deleteFirewalls>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RemoveFirewallRuleRequestBinder extends FirewallBinder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(List<String> payload) {
|
||||||
|
requestBuilder.append("<ws:removeFirewallRules>");
|
||||||
|
bindListWithTag(payload, "firewallRuleIds");
|
||||||
|
requestBuilder.append("</ws:removeFirewallRules>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.binder.loadbalancer;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class CreateLoadBalancerRequestBinder extends BaseProfitBricksRequestBinder<LoadBalancer.Request.CreatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
CreateLoadBalancerRequestBinder() {
|
||||||
|
super("loadbalancer");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(LoadBalancer.Request.CreatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:createLoadBalancer>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<dataCenterId>%s</dataCenterId>", payload.dataCenterId()))
|
||||||
|
.append(format("<loadBalancerName>%s</loadBalancerName>", payload.name()))
|
||||||
|
.append(format("<loadBalancerAlgorithm>%s</loadBalancerAlgorithm>", payload.algorithm()))
|
||||||
|
.append(format("<ip>%s</ip>", payload.ip()))
|
||||||
|
.append(format("<lanId>%s</lanId>", payload.lanId()));
|
||||||
|
for (String serverId : payload.serverIds())
|
||||||
|
requestBuilder.append(format("<serverIds>%s</serverIds>", serverId));
|
||||||
|
requestBuilder
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:createLoadBalancer>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.binder.loadbalancer;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
|
||||||
|
public class DeregisterLoadBalancerRequestBinder extends BaseProfitBricksRequestBinder<LoadBalancer.Request.DeregisterPayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
DeregisterLoadBalancerRequestBinder() {
|
||||||
|
super("loadbalancer");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(LoadBalancer.Request.DeregisterPayload payload) {
|
||||||
|
requestBuilder.append("<ws:deregisterServersOnLoadBalancer>");
|
||||||
|
for (String s : payload.serverIds())
|
||||||
|
requestBuilder.append(format("<serverIds>%s</serverIds>", s));
|
||||||
|
requestBuilder.append(format("<loadBalancerId>%s</loadBalancerId>", payload.id()))
|
||||||
|
.append("</ws:deregisterServersOnLoadBalancer>");
|
||||||
|
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.loadbalancer;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
|
||||||
|
public class RegisterLoadBalancerRequestBinder extends BaseProfitBricksRequestBinder<LoadBalancer.Request.RegisterPayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
RegisterLoadBalancerRequestBinder() {
|
||||||
|
super("loadbalancer");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(LoadBalancer.Request.RegisterPayload payload) {
|
||||||
|
requestBuilder
|
||||||
|
.append("<ws:registerServersOnLoadBalancer>")
|
||||||
|
.append(format("<loadBalancerId>%s</loadBalancerId>", payload.id()));
|
||||||
|
|
||||||
|
for (String s : payload.serverIds())
|
||||||
|
requestBuilder.append(format("<serverIds>%s</serverIds>", s));
|
||||||
|
requestBuilder.append("</ws:registerServersOnLoadBalancer>");
|
||||||
|
|
||||||
|
return requestBuilder.toString().replaceAll("\\s+", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.loadbalancer;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class UpdateLoadBalancerRequestBinder extends BaseProfitBricksRequestBinder<LoadBalancer.Request.UpdatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
UpdateLoadBalancerRequestBinder() {
|
||||||
|
super("loadbalancer");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(LoadBalancer.Request.UpdatePayload payload) {
|
||||||
|
return requestBuilder.append("<ws:updateLoadBalancer>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<loadBalancerId>%s</loadBalancerId>", payload.id()))
|
||||||
|
.append(formatIfNotEmpty("<loadBalancerName>%s</loadBalancerName>", payload.name()))
|
||||||
|
.append(formatIfNotEmpty("<loadBalancerAlgorithm>%s</loadBalancerAlgorithm>", payload.algorithm()))
|
||||||
|
.append(formatIfNotEmpty("<ip>%s</ip>", payload.ip()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:updateLoadBalancer>").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.nic;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
|
||||||
|
public class CreateNicRequestBinder extends BaseProfitBricksRequestBinder<Nic.Request.CreatePayload> {
|
||||||
|
|
||||||
|
private final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
CreateNicRequestBinder() {
|
||||||
|
super("nic");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Nic.Request.CreatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:createNic>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(formatIfNotEmpty("<ip>%s</ip>", payload.ip()))
|
||||||
|
.append(formatIfNotEmpty("<nicName>%s</nicName>", payload.name()))
|
||||||
|
.append(formatIfNotEmpty("<dhcpActive>%s</dhcpActive>", payload.dhcpActive()))
|
||||||
|
.append(format("<serverId>%s</serverId>", payload.serverId()))
|
||||||
|
.append(format("<lanId>%s</lanId>", payload.lanId()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:createNic>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.binder.nic;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class SetInternetAccessBinder extends BaseProfitBricksRequestBinder<Nic.Request.SetInternetAccessPayload> {
|
||||||
|
|
||||||
|
private final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
SetInternetAccessBinder() {
|
||||||
|
super("nic");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Nic.Request.SetInternetAccessPayload payload) {
|
||||||
|
requestBuilder.append("<ws:setInternetAccess>")
|
||||||
|
.append(format("<dataCenterId>%s</dataCenterId>", payload.dataCenterId()))
|
||||||
|
.append(format("<lanId>%s</lanId>", payload.lanId()))
|
||||||
|
.append(format("<internetAccess>%s</internetAccess>", payload.internetAccess()))
|
||||||
|
.append("</ws:setInternetAccess>");
|
||||||
|
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.nic;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class UpdateNicRequestBinder extends BaseProfitBricksRequestBinder<Nic.Request.UpdatePayload> {
|
||||||
|
|
||||||
|
private final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
UpdateNicRequestBinder() {
|
||||||
|
super("nic");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Nic.Request.UpdatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:updateNic>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<nicId>%s</nicId>", payload.id()))
|
||||||
|
.append(formatIfNotEmpty("<ip>%s</ip>", payload.ip()))
|
||||||
|
.append(formatIfNotEmpty("<nicName>%s</nicName>", payload.name()))
|
||||||
|
.append(formatIfNotEmpty("<dhcpActive>%s</dhcpActive>", payload.dhcpActive()))
|
||||||
|
.append(formatIfNotEmpty("<lanId>%s</lanId>", payload.lanId()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:updateNic>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.server;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
|
||||||
|
public class CreateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.CreatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
CreateServerRequestBinder() {
|
||||||
|
super("server");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Server.Request.CreatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:createServer>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<dataCenterId>%s</dataCenterId>", payload.dataCenterId()))
|
||||||
|
.append(format("<cores>%s</cores>", payload.cores()))
|
||||||
|
.append(format("<ram>%s</ram>", payload.ram()))
|
||||||
|
.append(formatIfNotEmpty("<serverName>%s</serverName>", payload.name()))
|
||||||
|
.append(formatIfNotEmpty("<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId()))
|
||||||
|
.append(formatIfNotEmpty("<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId()))
|
||||||
|
.append(formatIfNotEmpty("<internetAccess>%s</internetAccess>", payload.hasInternetAccess()))
|
||||||
|
.append(formatIfNotEmpty("<lanId>%s</lanId>", payload.lanId()))
|
||||||
|
.append(formatIfNotEmpty("<osType>%s</osType>", payload.osType()))
|
||||||
|
.append(formatIfNotEmpty("<availabilityZone>%s</availabilityZone>", payload.availabilityZone()))
|
||||||
|
.append(formatIfNotEmpty("<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug()))
|
||||||
|
.append(formatIfNotEmpty("<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:createServer>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.server;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
|
||||||
|
public class UpdateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.UpdatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
UpdateServerRequestBinder() {
|
||||||
|
super("server");
|
||||||
|
this.requestBuilder = new StringBuilder(128 * 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Server.Request.UpdatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:updateServer>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<serverId>%s</serverId>", payload.id()))
|
||||||
|
.append(format("<cores>%s</cores>", payload.cores()))
|
||||||
|
.append(format("<ram>%s</ram>", payload.ram()))
|
||||||
|
.append(formatIfNotEmpty("<serverName>%s</serverName>", payload.name()))
|
||||||
|
.append(formatIfNotEmpty("<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId()))
|
||||||
|
.append(formatIfNotEmpty("<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId()))
|
||||||
|
.append(formatIfNotEmpty("<osType>%s</osType>", payload.osType()))
|
||||||
|
.append(formatIfNotEmpty("<availabilityZone>%s</availabilityZone>", payload.availabilityZone()))
|
||||||
|
.append(formatIfNotEmpty("<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug()))
|
||||||
|
.append(formatIfNotEmpty("<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:updateServer>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.snapshot;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class CreateSnapshotRequestBinder extends BaseProfitBricksRequestBinder<Snapshot.Request.CreatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
protected CreateSnapshotRequestBinder() {
|
||||||
|
super("snapshot");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Snapshot.Request.CreatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:createSnapshot>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<storageId>%s</storageId>", payload.storageId()))
|
||||||
|
.append(formatIfNotEmpty("<description>%s</description>", payload.description()))
|
||||||
|
.append(formatIfNotEmpty("<snapshotName>%s</snapshotName>", payload.name()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:createSnapshot>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.snapshot;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class RollbackSnapshotRequestBinder extends BaseProfitBricksRequestBinder<Snapshot.Request.RollbackPayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
protected RollbackSnapshotRequestBinder() {
|
||||||
|
super("snapshot");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Snapshot.Request.RollbackPayload payload) {
|
||||||
|
requestBuilder.append("<ws:rollbackSnapshot>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<snapshotId>%s</snapshotId>", payload.snapshotId()))
|
||||||
|
.append(format("<storageId>%s</storageId>", payload.storageId()))
|
||||||
|
.append("</request>")
|
||||||
|
.append("</ws:rollbackSnapshot>");
|
||||||
|
return requestBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.binder.snapshot;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
|
||||||
|
public class UpdateSnapshotRequestBinder extends BaseProfitBricksRequestBinder<Snapshot.Request.UpdatePayload> {
|
||||||
|
|
||||||
|
protected final StringBuilder requestBuilder;
|
||||||
|
|
||||||
|
protected UpdateSnapshotRequestBinder() {
|
||||||
|
super("snapshot");
|
||||||
|
this.requestBuilder = new StringBuilder(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createPayload(Snapshot.Request.UpdatePayload payload) {
|
||||||
|
requestBuilder.append("<ws:updateSnapshot>")
|
||||||
|
.append("<request>")
|
||||||
|
.append(format("<snapshotId>%s</snapshotId>", payload.id()))
|
||||||
|
.append(format("<description>%s</description>", payload.description()))
|
||||||
|
.append(format("<snapshotName>%s</snapshotName>", payload.name()))
|
||||||
|
.append(formatIfNotEmpty("<bootable>%s</bootable>", payload.bootable()))
|
||||||
|
.append(formatIfNotEmpty("<osType>%s</osType>", payload.osType()))
|
||||||
|
.append(formatIfNotEmpty("<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<cpuHotUnPlug>%s</cpuHotUnPlug>", payload.isCpuHotUnPlug()))
|
||||||
|
.append(formatIfNotEmpty("<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug()))
|
||||||
|
.append(formatIfNotEmpty("<ramHotUnPlug>%s</ramHotUnPlug>", payload.isRamHotUnPlug()))
|
||||||
|
.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:updateSnapshot>");
|
||||||
|
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.imagePassword()))
|
||||||
|
.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,483 @@
|
||||||
|
/*
|
||||||
|
* 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.compute;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static com.google.common.util.concurrent.Futures.allAsList;
|
||||||
|
import static com.google.common.util.concurrent.Futures.getUnchecked;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_PREDICATE_DATACENTER;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
|
import org.jclouds.compute.domain.Processor;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.compute.domain.Volume;
|
||||||
|
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
|
import org.jclouds.compute.util.ComputeServiceUtils;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LocationScope;
|
||||||
|
import org.jclouds.domain.LoginCredentials;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||||
|
import org.jclouds.profitbricks.compute.concurrent.ProvisioningJob;
|
||||||
|
import org.jclouds.profitbricks.compute.concurrent.ProvisioningManager;
|
||||||
|
import org.jclouds.profitbricks.compute.function.ProvisionableToImage;
|
||||||
|
import org.jclouds.profitbricks.compute.strategy.TemplateWithDataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.Image;
|
||||||
|
import org.jclouds.profitbricks.domain.Provisionable;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
import org.jclouds.profitbricks.domain.Storage;
|
||||||
|
import org.jclouds.profitbricks.features.ServerApi;
|
||||||
|
import org.jclouds.profitbricks.util.Passwords;
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class ProfitBricksComputeServiceAdapter implements ComputeServiceAdapter<Server, Hardware, Provisionable, Location> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
private final ProfitBricksApi api;
|
||||||
|
private final Predicate<String> waitDcUntilAvailable;
|
||||||
|
private final ListeningExecutorService executorService;
|
||||||
|
private final ProvisioningJob.Factory jobFactory;
|
||||||
|
private final ProvisioningManager provisioningManager;
|
||||||
|
|
||||||
|
private static final Integer DEFAULT_LAN_ID = 1;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ProfitBricksComputeServiceAdapter(ProfitBricksApi api,
|
||||||
|
@Named(POLL_PREDICATE_DATACENTER) Predicate<String> waitDcUntilAvailable,
|
||||||
|
@Named(PROPERTY_USER_THREADS) ListeningExecutorService executorService,
|
||||||
|
ProvisioningJob.Factory jobFactory,
|
||||||
|
ProvisioningManager provisioningManager) {
|
||||||
|
this.api = api;
|
||||||
|
this.waitDcUntilAvailable = waitDcUntilAvailable;
|
||||||
|
this.executorService = executorService;
|
||||||
|
this.jobFactory = jobFactory;
|
||||||
|
this.provisioningManager = provisioningManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
|
||||||
|
checkArgument(template instanceof TemplateWithDataCenter, "This implementation requires a TemplateWithDataCenter");
|
||||||
|
return createNodeWithGroupEncodedIntoName(group, name, TemplateWithDataCenter.class.cast(template));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String group, String name, TemplateWithDataCenter template) {
|
||||||
|
checkArgument(template.getLocation().getScope() == LocationScope.ZONE, "Template must use a ZONE-scoped location");
|
||||||
|
final String dataCenterId = template.getDataCenter().id();
|
||||||
|
|
||||||
|
Hardware hardware = template.getHardware();
|
||||||
|
|
||||||
|
TemplateOptions options = template.getOptions();
|
||||||
|
final String loginUser = isNullOrEmpty(options.getLoginUser()) ? "root" : options.getLoginUser();
|
||||||
|
final String password = options.hasLoginPassword() ? options.getLoginPassword() : Passwords.generate();
|
||||||
|
|
||||||
|
final org.jclouds.compute.domain.Image image = template.getImage();
|
||||||
|
|
||||||
|
// provision all storages based on hardware
|
||||||
|
List<? extends Volume> volumes = hardware.getVolumes();
|
||||||
|
List<String> storageIds = Lists.newArrayListWithExpectedSize(volumes.size());
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
for (final Volume volume : volumes)
|
||||||
|
try {
|
||||||
|
logger.trace("<< provisioning storage '%s'", volume);
|
||||||
|
final Storage.Request.CreatePayload.Builder storageBuilder = Storage.Request.creatingBuilder();
|
||||||
|
if (i == 1) {
|
||||||
|
storageBuilder.mountImageId(image.getId());
|
||||||
|
// we don't need to pass password to the API if we're using a snapshot
|
||||||
|
Provisionable.Type provisionableType = Provisionable.Type.fromValue(
|
||||||
|
image.getUserMetadata().get(ProvisionableToImage.KEY_PROVISIONABLE_TYPE));
|
||||||
|
if (provisionableType == Provisionable.Type.IMAGE)
|
||||||
|
storageBuilder.imagePassword(password);
|
||||||
|
}
|
||||||
|
storageBuilder.dataCenterId(dataCenterId)
|
||||||
|
.name(format("%s-disk-%d", name, i++))
|
||||||
|
.size(volume.getSize());
|
||||||
|
|
||||||
|
String storageId = (String) provisioningManager.provision(jobFactory.create(dataCenterId, new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
return api.storageApi().createStorage(storageBuilder.build());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
storageIds.add(storageId);
|
||||||
|
logger.trace(">> provisioning complete for storage. returned id='%s'", storageId);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (i - 1 == 1) // if first storage (one with image) provisioning fails; stop method
|
||||||
|
throw Throwables.propagate(ex);
|
||||||
|
logger.warn(ex, ">> failed to provision storage. skipping..");
|
||||||
|
}
|
||||||
|
|
||||||
|
int lanId = DEFAULT_LAN_ID;
|
||||||
|
if (options.getNetworks() != null)
|
||||||
|
try {
|
||||||
|
String networkId = Iterables.get(options.getNetworks(), 0);
|
||||||
|
lanId = Integer.valueOf(networkId);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.warn("no valid network id found from options. using default id='%d'", DEFAULT_LAN_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Double cores = ComputeServiceUtils.getCores(hardware);
|
||||||
|
|
||||||
|
// provision server and connect boot storage (first provisioned)
|
||||||
|
String serverId = null;
|
||||||
|
try {
|
||||||
|
String storageBootDeviceId = Iterables.get(storageIds, 0); // must have atleast 1
|
||||||
|
final Server.Request.CreatePayload serverRequest = Server.Request.creatingBuilder()
|
||||||
|
.dataCenterId(dataCenterId)
|
||||||
|
.name(name)
|
||||||
|
.bootFromStorageId(storageBootDeviceId)
|
||||||
|
.cores(cores.intValue())
|
||||||
|
.ram(hardware.getRam())
|
||||||
|
.availabilityZone(AvailabilityZone.AUTO)
|
||||||
|
.hasInternetAccess(true)
|
||||||
|
.lanId(lanId)
|
||||||
|
.build();
|
||||||
|
logger.trace("<< provisioning server '%s'", serverRequest);
|
||||||
|
|
||||||
|
serverId = (String) provisioningManager.provision(jobFactory.create(dataCenterId, new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
return api.serverApi().createServer(serverRequest);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
logger.trace(">> provisioning complete for server. returned id='%s'", serverId);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error(ex, ">> failed to provision server. rollbacking..");
|
||||||
|
destroyStorages(storageIds, dataCenterId);
|
||||||
|
throw Throwables.propagate(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect the rest of storages to server; delete if fails
|
||||||
|
final int storageCount = storageIds.size();
|
||||||
|
for (int j = 1; j < storageCount; j++) { // skip first; already connected
|
||||||
|
String storageId = storageIds.get(j);
|
||||||
|
try {
|
||||||
|
logger.trace("<< connecting storage '%s' to server '%s'", storageId, serverId);
|
||||||
|
final Storage.Request.ConnectPayload request = Storage.Request.connectingBuilder()
|
||||||
|
.storageId(storageId)
|
||||||
|
.serverId(serverId)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
provisioningManager.provision(jobFactory.create(group, new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
return api.storageApi().connectStorageToServer(request);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
logger.trace(">> storage connected.");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// delete unconnected storage
|
||||||
|
logger.warn(ex, ">> failed to connect storage '%s'. deleting..", storageId);
|
||||||
|
destroyStorage(storageId, dataCenterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last paranoid check
|
||||||
|
waitDcUntilAvailable.apply(dataCenterId);
|
||||||
|
|
||||||
|
LoginCredentials serverCredentials = LoginCredentials.builder()
|
||||||
|
.user(loginUser)
|
||||||
|
.password(password)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Server server = getNode(serverId);
|
||||||
|
|
||||||
|
return new NodeAndInitialCredentials<Server>(server, serverId, serverCredentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Hardware> listHardwareProfiles() {
|
||||||
|
// Max [cores=48] [disk size per storage=2048GB] [ram=200704 MB]
|
||||||
|
List<Hardware> hardwares = Lists.newArrayList();
|
||||||
|
for (int core = 1; core <= 48; core++)
|
||||||
|
for (int ram : new int[]{1024, 2 * 1024, 4 * 1024, 8 * 1024,
|
||||||
|
10 * 1024, 16 * 1024, 24 * 1024, 28 * 1024, 32 * 1024})
|
||||||
|
for (float size : new float[]{10, 20, 30, 50, 80, 100, 150, 200, 250, 500}) {
|
||||||
|
String id = String.format("cpu=%d,ram=%s,disk=%f", core, ram, size);
|
||||||
|
hardwares.add(new HardwareBuilder()
|
||||||
|
.ids(id)
|
||||||
|
.ram(ram)
|
||||||
|
.hypervisor("kvm")
|
||||||
|
.name(id)
|
||||||
|
.processor(new Processor(core, 1d))
|
||||||
|
.volume(new VolumeImpl(size, true, true))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
return hardwares;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Provisionable> listImages() {
|
||||||
|
// fetch images..
|
||||||
|
ListenableFuture<List<Image>> images = executorService.submit(new Callable<List<Image>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Image> call() throws Exception {
|
||||||
|
logger.trace("<< fetching images..");
|
||||||
|
// Filter HDD types only, since JClouds doesn't have a concept of "CD-ROM" anyway
|
||||||
|
Iterable<Image> filteredImages = Iterables.filter(api.imageApi().getAllImages(), new Predicate<Image>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Image image) {
|
||||||
|
return image.type() == Image.Type.HDD;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
logger.trace(">> images fetched.");
|
||||||
|
|
||||||
|
return ImmutableList.copyOf(filteredImages);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
// and snapshots at the same time
|
||||||
|
ListenableFuture<List<Snapshot>> snapshots = executorService.submit(new Callable<List<Snapshot>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Snapshot> call() throws Exception {
|
||||||
|
logger.trace("<< fetching snapshots");
|
||||||
|
List<Snapshot> remoteSnapshots = api.snapshotApi().getAllSnapshots();
|
||||||
|
logger.trace(">> snapshots feched.");
|
||||||
|
|
||||||
|
return remoteSnapshots;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return Iterables.concat(getUnchecked(images), getUnchecked(snapshots));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Provisionable getImage(String id) {
|
||||||
|
// try search images
|
||||||
|
logger.trace("<< searching for image with id=%s", id);
|
||||||
|
Image image = api.imageApi().getImage(id);
|
||||||
|
if (image != null) {
|
||||||
|
logger.trace(">> found image [%s].", image.name());
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
// try search snapshots
|
||||||
|
logger.trace("<< not found from images. searching for snapshot with id=%s", id);
|
||||||
|
Snapshot snapshot = api.snapshotApi().getSnapshot(id);
|
||||||
|
if (snapshot != null) {
|
||||||
|
logger.trace(">> found snapshot [%s]", snapshot.name());
|
||||||
|
return snapshot;
|
||||||
|
}
|
||||||
|
throw new ResourceNotFoundException("No image/snapshot with id '" + id + "' was found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Location> listLocations() {
|
||||||
|
// Will never be called
|
||||||
|
throw new UnsupportedOperationException("Locations are configured in jclouds properties");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Server getNode(String id) {
|
||||||
|
logger.trace("<< searching for server with id=%s", id);
|
||||||
|
|
||||||
|
Server server = api.serverApi().getServer(id);
|
||||||
|
if (server != null)
|
||||||
|
logger.trace(">> found server [%s]", server.name());
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyNode(String nodeId) {
|
||||||
|
ServerApi serverApi = api.serverApi();
|
||||||
|
Server server = serverApi.getServer(nodeId);
|
||||||
|
if (server != null) {
|
||||||
|
String dataCenterId = server.dataCenter().id();
|
||||||
|
for (Storage storage : server.storages())
|
||||||
|
destroyStorage(storage.id(), dataCenterId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
destroyServer(nodeId, dataCenterId);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.warn(ex, ">> failed to delete server with id=%s", nodeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rebootNode(final String id) {
|
||||||
|
// Fail pre-emptively if not found
|
||||||
|
final Server node = getRequiredNode(id);
|
||||||
|
final DataCenter dataCenter = node.dataCenter();
|
||||||
|
provisioningManager.provision(jobFactory.create(dataCenter.id(), new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
api.serverApi().resetServer(id);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resumeNode(final String id) {
|
||||||
|
final Server node = getRequiredNode(id);
|
||||||
|
if (node.status() == Server.Status.RUNNING)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final DataCenter dataCenter = node.dataCenter();
|
||||||
|
provisioningManager.provision(jobFactory.create(dataCenter.id(), new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
api.serverApi().startServer(id);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suspendNode(final String id) {
|
||||||
|
final Server node = getRequiredNode(id);
|
||||||
|
// Intentionally didn't include SHUTDOWN (only achieved via UI; soft-shutdown).
|
||||||
|
// A SHUTOFF server is no longer billed, so we execute method for all other status
|
||||||
|
if (node.status() == Server.Status.SHUTOFF)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final DataCenter dataCenter = node.dataCenter();
|
||||||
|
provisioningManager.provision(jobFactory.create(dataCenter.id(), new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
api.serverApi().stopServer(id);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Server> listNodes() {
|
||||||
|
logger.trace(">> fetching all servers..");
|
||||||
|
List<Server> servers = api.serverApi().getAllServers();
|
||||||
|
logger.trace(">> servers fetched.");
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Server> listNodesByIds(final Iterable<String> ids) {
|
||||||
|
// Only fetch the requested nodes. Do it in parallel.
|
||||||
|
ListenableFuture<List<Server>> futures = allAsList(transform(ids,
|
||||||
|
new Function<String, ListenableFuture<Server>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<Server> apply(final String input) {
|
||||||
|
return executorService.submit(new Callable<Server>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Server call() throws Exception {
|
||||||
|
return getNode(input);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
return getUnchecked(futures);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyServer(final String serverId, final String dataCenterId) {
|
||||||
|
try {
|
||||||
|
logger.trace("<< deleting server with id=%s", serverId);
|
||||||
|
provisioningManager.provision(jobFactory.create(dataCenterId, new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
api.serverApi().deleteServer(serverId);
|
||||||
|
|
||||||
|
return serverId;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
logger.trace(">> server '%s' deleted.", serverId);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.warn(ex, ">> failed to delete server with id=%s", serverId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyStorages(List<String> storageIds, String dataCenterId) {
|
||||||
|
for (String storageId : storageIds)
|
||||||
|
destroyStorage(storageId, dataCenterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyStorage(final String storageId, final String dataCenterId) {
|
||||||
|
try {
|
||||||
|
logger.trace("<< deleting storage with id=%s", storageId);
|
||||||
|
provisioningManager.provision(jobFactory.create(dataCenterId, new Supplier<Object>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
api.storageApi().deleteStorage(storageId);
|
||||||
|
|
||||||
|
return storageId;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
logger.trace(">> storage '%s' deleted.", storageId);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.warn(ex, ">> failed to delete storage with id=%s", storageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Server getRequiredNode(String nodeId) {
|
||||||
|
Server node = getNode(nodeId);
|
||||||
|
if (node == null)
|
||||||
|
throw new ResourceNotFoundException("Node with id'" + nodeId + "' was not found.");
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.compute.concurrent;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_PREDICATE_DATACENTER;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
public class ProvisioningJob implements Callable {
|
||||||
|
|
||||||
|
public interface Factory {
|
||||||
|
|
||||||
|
ProvisioningJob create(String group, Supplier<Object> operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Predicate<String> waitDataCenterUntilReady;
|
||||||
|
private final String group;
|
||||||
|
private final Supplier<Object> operation;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ProvisioningJob(@Named(POLL_PREDICATE_DATACENTER) Predicate<String> waitDataCenterUntilReady,
|
||||||
|
@Assisted String group, @Assisted Supplier<Object> operation) {
|
||||||
|
this.waitDataCenterUntilReady = waitDataCenterUntilReady;
|
||||||
|
this.group = checkNotNull(group, "group cannot be null");
|
||||||
|
this.operation = checkNotNull(operation, "operation cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
waitDataCenterUntilReady.apply(group);
|
||||||
|
Object obj = operation.get();
|
||||||
|
waitDataCenterUntilReady.apply(group);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* 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.compute.concurrent;
|
||||||
|
|
||||||
|
import static com.google.common.util.concurrent.Futures.getUnchecked;
|
||||||
|
import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.config.WithSubmissionTrace;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegates {@link Job} to single-threaded executor services based on it's group.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final class ProvisioningManager implements Closeable {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
private final Map<String, ListeningExecutorService> workers
|
||||||
|
= new ConcurrentHashMap<String, ListeningExecutorService>(1);
|
||||||
|
|
||||||
|
private final AtomicBoolean terminated = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
public Object provision(ProvisioningJob job) {
|
||||||
|
if (terminated.get()) {
|
||||||
|
logger.warn("Job(%s) submitted but the provisioning manager is already closed", job);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Job(%s) submitted to group '%s'", job, job.getGroup());
|
||||||
|
ListeningExecutorService workerGroup = getWorkerGroup(job.getGroup());
|
||||||
|
return getUnchecked(workerGroup.submit(job));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ListeningExecutorService newExecutorService() {
|
||||||
|
return WithSubmissionTrace.wrap(listeningDecorator(Executors.newSingleThreadExecutor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void newWorkerGroupIfAbsent(String name) {
|
||||||
|
if (!workers.containsKey(name))
|
||||||
|
workers.put(name, newExecutorService());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ListeningExecutorService getWorkerGroup(String name) {
|
||||||
|
newWorkerGroupIfAbsent(name);
|
||||||
|
return workers.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
terminated.set(true); // Do not allow to enqueue more jobs
|
||||||
|
Collection<ListeningExecutorService> executors = workers.values();
|
||||||
|
for (ListeningExecutorService executor : executors) {
|
||||||
|
List<Runnable> runnables = executor.shutdownNow();
|
||||||
|
if (!runnables.isEmpty())
|
||||||
|
logger.warn("when shutting down executor %s, runnables outstanding: %s", executor, runnables);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,223 @@
|
||||||
|
/*
|
||||||
|
* 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.compute.config;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_INITIAL_PERIOD;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_MAX_PERIOD;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_PREDICATE_DATACENTER;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_PREDICATE_SNAPSHOT;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.TIMEOUT_DATACENTER_AVAILABLE;
|
||||||
|
import static org.jclouds.util.Predicates2.retry;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
|
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.Volume;
|
||||||
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.functions.IdentityFunction;
|
||||||
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||||
|
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
|
||||||
|
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||||
|
import org.jclouds.profitbricks.compute.ProfitBricksComputeServiceAdapter;
|
||||||
|
import org.jclouds.profitbricks.compute.concurrent.ProvisioningJob;
|
||||||
|
import org.jclouds.profitbricks.compute.concurrent.ProvisioningManager;
|
||||||
|
import org.jclouds.profitbricks.compute.function.ProvisionableToImage;
|
||||||
|
import org.jclouds.profitbricks.compute.function.ServerToNodeMetadata;
|
||||||
|
import org.jclouds.profitbricks.compute.function.StorageToVolume;
|
||||||
|
import org.jclouds.profitbricks.compute.strategy.AssignDataCenterToTemplate;
|
||||||
|
import org.jclouds.profitbricks.domain.Provisionable;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.domain.Storage;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
public class ProfitBricksComputeServiceContextModule extends
|
||||||
|
ComputeServiceAdapterContextModule<Server, Hardware, Provisionable, Location> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
super.configure();
|
||||||
|
|
||||||
|
install(new FactoryModuleBuilder().build(ProvisioningJob.Factory.class));
|
||||||
|
|
||||||
|
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
|
||||||
|
|
||||||
|
bind(CreateNodesInGroupThenAddToSet.class).to(AssignDataCenterToTemplate.class).in(Scopes.SINGLETON);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<ComputeServiceAdapter<Server, Hardware, Provisionable, Location>>() {
|
||||||
|
}).to(ProfitBricksComputeServiceAdapter.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||||
|
}).to(ServerToNodeMetadata.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Provisionable, Image>>() {
|
||||||
|
}).to(ProvisionableToImage.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Storage, Volume>>() {
|
||||||
|
}).to(StorageToVolume.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
|
||||||
|
}).to(Class.class.cast(IdentityFunction.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@Named(POLL_PREDICATE_DATACENTER)
|
||||||
|
Predicate<String> provideDataCenterAvailablePredicate(
|
||||||
|
final ProfitBricksApi api, ComputeConstants constants) {
|
||||||
|
return retry(new DataCenterProvisioningStatePredicate(
|
||||||
|
api, ProvisioningState.AVAILABLE),
|
||||||
|
constants.pollTimeout(), constants.pollPeriod(), constants.pollMaxPeriod(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named(TIMEOUT_NODE_RUNNING)
|
||||||
|
Predicate<String> provideServerRunningPredicate(final ProfitBricksApi api, ComputeConstants constants) {
|
||||||
|
return retry(new ServerStatusPredicate(
|
||||||
|
api, Server.Status.RUNNING),
|
||||||
|
constants.pollTimeout(), constants.pollPeriod(), constants.pollMaxPeriod(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named(TIMEOUT_NODE_SUSPENDED)
|
||||||
|
Predicate<String> provideServerSuspendedPredicate(final ProfitBricksApi api, ComputeConstants constants) {
|
||||||
|
return retry(new ServerStatusPredicate(
|
||||||
|
api, Server.Status.SHUTOFF),
|
||||||
|
constants.pollTimeout(), constants.pollPeriod(), constants.pollMaxPeriod(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ProvisioningManager provideProvisioningManager(Closer closer) {
|
||||||
|
ProvisioningManager provisioningManager = new ProvisioningManager();
|
||||||
|
closer.addToClose(provisioningManager);
|
||||||
|
|
||||||
|
return provisioningManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@Named(POLL_PREDICATE_SNAPSHOT)
|
||||||
|
Predicate<String> provideSnapshotAvailablePredicate(final ProfitBricksApi api, ComputeConstants constants) {
|
||||||
|
return retry(new SnapshotProvisioningStatePredicate(
|
||||||
|
api, ProvisioningState.AVAILABLE),
|
||||||
|
constants.pollTimeout(), constants.pollPeriod(), constants.pollMaxPeriod(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class DataCenterProvisioningStatePredicate implements Predicate<String> {
|
||||||
|
|
||||||
|
private final ProfitBricksApi api;
|
||||||
|
private final ProvisioningState expectedState;
|
||||||
|
|
||||||
|
public DataCenterProvisioningStatePredicate(ProfitBricksApi api, ProvisioningState expectedState) {
|
||||||
|
this.api = checkNotNull(api, "api must not be null");
|
||||||
|
this.expectedState = checkNotNull(expectedState, "expectedState must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(String input) {
|
||||||
|
checkNotNull(input, "datacenter id");
|
||||||
|
return api.dataCenterApi().getDataCenterState(input) == expectedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ServerStatusPredicate implements Predicate<String> {
|
||||||
|
|
||||||
|
private final ProfitBricksApi api;
|
||||||
|
private final Server.Status expectedStatus;
|
||||||
|
|
||||||
|
public ServerStatusPredicate(ProfitBricksApi api, Server.Status expectedStatus) {
|
||||||
|
this.api = checkNotNull(api, "api must not be null");
|
||||||
|
this.expectedStatus = checkNotNull(expectedStatus, "expectedStatus must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(String input) {
|
||||||
|
checkNotNull(input, "server id");
|
||||||
|
return api.serverApi().getServer(input).status() == expectedStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class SnapshotProvisioningStatePredicate implements Predicate<String> {
|
||||||
|
|
||||||
|
private final ProfitBricksApi api;
|
||||||
|
private final ProvisioningState expectedState;
|
||||||
|
|
||||||
|
public SnapshotProvisioningStatePredicate(ProfitBricksApi api, ProvisioningState expectedState) {
|
||||||
|
this.api = checkNotNull(api, "api must not be null");
|
||||||
|
this.expectedState = checkNotNull(expectedState, "expectedState must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(String input) {
|
||||||
|
checkNotNull(input, "snapshot id");
|
||||||
|
return api.snapshotApi().getSnapshot(input).state() == expectedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class ComputeConstants {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named(TIMEOUT_DATACENTER_AVAILABLE)
|
||||||
|
private String pollTimeout;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named(POLL_INITIAL_PERIOD)
|
||||||
|
private String pollPeriod;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named(POLL_MAX_PERIOD)
|
||||||
|
private String pollMaxPeriod;
|
||||||
|
|
||||||
|
public long pollTimeout() {
|
||||||
|
return Long.parseLong(pollTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long pollPeriod() {
|
||||||
|
return Long.parseLong(pollPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long pollMaxPeriod() {
|
||||||
|
return Long.parseLong(pollMaxPeriod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,241 @@
|
||||||
|
/*
|
||||||
|
* 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.compute.function;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.collect.Iterables.find;
|
||||||
|
import static org.jclouds.location.predicates.LocationPredicates.idEquals;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.ImageBuilder;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.domain.OsType;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
import org.jclouds.profitbricks.domain.Provisionable;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
public class ProvisionableToImage implements Function<Provisionable, Image> {
|
||||||
|
|
||||||
|
public static final String KEY_PROVISIONABLE_TYPE = "provisionableType";
|
||||||
|
|
||||||
|
private final ImageToImage fnImageToImage;
|
||||||
|
private final SnapshotToImage fnSnapshotToImage;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ProvisionableToImage(@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
|
this.fnImageToImage = new ImageToImage(locations);
|
||||||
|
this.fnSnapshotToImage = new SnapshotToImage(locations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image apply(Provisionable input) {
|
||||||
|
checkNotNull(input, "Cannot convert null input");
|
||||||
|
|
||||||
|
if (input instanceof org.jclouds.profitbricks.domain.Image)
|
||||||
|
return fnImageToImage.apply((org.jclouds.profitbricks.domain.Image) input);
|
||||||
|
|
||||||
|
else if (input instanceof Snapshot)
|
||||||
|
return fnSnapshotToImage.apply((Snapshot) input);
|
||||||
|
|
||||||
|
else
|
||||||
|
throw new UnsupportedOperationException("No implementation found for provisionable of concrete type '"
|
||||||
|
+ input.getClass().getCanonicalName() + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OsFamily mapOsFamily(OsType osType) {
|
||||||
|
if (osType == null)
|
||||||
|
return OsFamily.UNRECOGNIZED;
|
||||||
|
switch (osType) {
|
||||||
|
case WINDOWS:
|
||||||
|
return OsFamily.WINDOWS;
|
||||||
|
case LINUX:
|
||||||
|
return OsFamily.LINUX;
|
||||||
|
case UNRECOGNIZED:
|
||||||
|
case OTHER:
|
||||||
|
default:
|
||||||
|
return OsFamily.UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ImageToImage implements ImageFunction<org.jclouds.profitbricks.domain.Image> {
|
||||||
|
|
||||||
|
private static final Pattern HAS_NUMBERS = Pattern.compile(".*\\d+.*");
|
||||||
|
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
|
||||||
|
ImageToImage(Supplier<Set<? extends Location>> locations) {
|
||||||
|
this.locations = locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image apply(org.jclouds.profitbricks.domain.Image from) {
|
||||||
|
String desc = from.name();
|
||||||
|
OsFamily osFamily = parseOsFamily(desc, from.osType());
|
||||||
|
Location location = find(locations.get(), idEquals(from.location().getId()));
|
||||||
|
|
||||||
|
OperatingSystem os = OperatingSystem.builder()
|
||||||
|
.description(osFamily.value())
|
||||||
|
.family(osFamily)
|
||||||
|
.version(parseVersion(desc))
|
||||||
|
.is64Bit(is64Bit(desc, from.type()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return addTypeMetadata(new ImageBuilder()
|
||||||
|
.ids(from.id())
|
||||||
|
.name(desc)
|
||||||
|
.location(location)
|
||||||
|
.status(Image.Status.AVAILABLE)
|
||||||
|
.operatingSystem(os))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private OsFamily parseOsFamily(String from, OsType fallbackValue) {
|
||||||
|
if (from != null)
|
||||||
|
try {
|
||||||
|
// ProfitBricks images names are usually in format:
|
||||||
|
// [osType]-[version]-[subversion]-..-[date-created]
|
||||||
|
String desc = from.toUpperCase().split("-")[0];
|
||||||
|
OsFamily osFamily = OsFamily.fromValue(desc);
|
||||||
|
checkArgument(osFamily != OsFamily.UNRECOGNIZED);
|
||||||
|
|
||||||
|
return osFamily;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
return mapOsFamily(fallbackValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String parseVersion(String from) {
|
||||||
|
if (from != null) {
|
||||||
|
String[] split = from.toLowerCase().split("-");
|
||||||
|
if (split.length >= 2) {
|
||||||
|
int i = 1; // usually on second token
|
||||||
|
String version = split[i];
|
||||||
|
while (!HAS_NUMBERS.matcher(version).matches())
|
||||||
|
version = split[++i];
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean is64Bit(String from, org.jclouds.profitbricks.domain.Image.Type type) {
|
||||||
|
switch (type) {
|
||||||
|
case CDROM:
|
||||||
|
if (!Strings.isNullOrEmpty(from))
|
||||||
|
return from.matches("x86_64|amd64");
|
||||||
|
case HDD: // HDD provided by ProfitBricks are always 64-bit
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImageBuilder addTypeMetadata(ImageBuilder builder) {
|
||||||
|
return builder.userMetadata(ImmutableMap.of(KEY_PROVISIONABLE_TYPE, Provisionable.Type.IMAGE.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SnapshotToImage implements ImageFunction<Snapshot> {
|
||||||
|
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
|
||||||
|
SnapshotToImage(Supplier<Set<? extends Location>> locations) {
|
||||||
|
this.locations = locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image apply(Snapshot from) {
|
||||||
|
String textToParse = from.name() + from.description();
|
||||||
|
OsFamily osFamily = parseOsFamily(textToParse, from.osType());
|
||||||
|
Location location = find(locations.get(), idEquals(from.location().getId()));
|
||||||
|
|
||||||
|
OperatingSystem os = OperatingSystem.builder()
|
||||||
|
.description(osFamily.value())
|
||||||
|
.family(osFamily)
|
||||||
|
.is64Bit(true)
|
||||||
|
.version("00.00")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return addTypeMetadata(new ImageBuilder()
|
||||||
|
.ids(from.id())
|
||||||
|
.name(from.name())
|
||||||
|
.description(from.description())
|
||||||
|
.location(location)
|
||||||
|
.status(mapStatus(from.state()))
|
||||||
|
.operatingSystem(os))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private OsFamily parseOsFamily(String text, OsType fallbackValue) {
|
||||||
|
if (text != null)
|
||||||
|
try {
|
||||||
|
// Attempt parsing OsFamily by scanning name and description
|
||||||
|
// @see ProfitBricksComputeServiceAdapter#L190
|
||||||
|
OsFamily[] families = OsFamily.values();
|
||||||
|
for (OsFamily family : families)
|
||||||
|
if (text.contains(family.value()))
|
||||||
|
return family;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
return mapOsFamily(fallbackValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Image.Status mapStatus(ProvisioningState state) {
|
||||||
|
if (state == null)
|
||||||
|
return Image.Status.UNRECOGNIZED;
|
||||||
|
switch (state) {
|
||||||
|
case AVAILABLE:
|
||||||
|
return Image.Status.AVAILABLE;
|
||||||
|
case DELETED:
|
||||||
|
return Image.Status.DELETED;
|
||||||
|
case ERROR:
|
||||||
|
return Image.Status.ERROR;
|
||||||
|
case INACTIVE:
|
||||||
|
case INPROCESS:
|
||||||
|
return Image.Status.PENDING;
|
||||||
|
default:
|
||||||
|
return Image.Status.UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImageBuilder addTypeMetadata(ImageBuilder builder) {
|
||||||
|
return builder.userMetadata(ImmutableMap.of(KEY_PROVISIONABLE_TYPE, Provisionable.Type.SNAPSHOT.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface ImageFunction<T extends Provisionable> extends Function<T, Image> {
|
||||||
|
|
||||||
|
ImageBuilder addTypeMetadata(ImageBuilder builder);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,168 @@
|
||||||
|
/*
|
||||||
|
* 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.compute.function;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Predicates.not;
|
||||||
|
import static com.google.common.collect.Iterables.find;
|
||||||
|
import static org.jclouds.location.predicates.LocationPredicates.idEquals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
|
import org.jclouds.compute.domain.Processor;
|
||||||
|
import org.jclouds.compute.domain.Volume;
|
||||||
|
import org.jclouds.compute.functions.GroupNamingConvention;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
import org.jclouds.profitbricks.domain.OsType;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.domain.Storage;
|
||||||
|
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
|
private final Function<Storage, Volume> fnVolume;
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
private final Function<List<Nic>, List<String>> fnCollectIps;
|
||||||
|
private final ProfitBricksApi api;
|
||||||
|
|
||||||
|
private final GroupNamingConvention groupNamingConvention;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ServerToNodeMetadata(Function<Storage, Volume> fnVolume,
|
||||||
|
@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
|
ProfitBricksApi api,
|
||||||
|
GroupNamingConvention.Factory groupNamingConvention) {
|
||||||
|
this.fnVolume = fnVolume;
|
||||||
|
this.locations = locations;
|
||||||
|
this.api = api;
|
||||||
|
this.groupNamingConvention = groupNamingConvention.createWithoutPrefix();
|
||||||
|
this.fnCollectIps = new Function<List<Nic>, List<String>>() {
|
||||||
|
@Override
|
||||||
|
public List<String> apply(List<Nic> in) {
|
||||||
|
List<String> ips = Lists.newArrayListWithExpectedSize(in.size());
|
||||||
|
for (Nic nic : in)
|
||||||
|
ips.addAll(nic.ips());
|
||||||
|
return ips;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata apply(final Server server) {
|
||||||
|
checkNotNull(server, "Null server");
|
||||||
|
// Location is not populated in the datacenter on a server response
|
||||||
|
DataCenter dataCenter = api.dataCenterApi().getDataCenter(server.dataCenter().id());
|
||||||
|
Location location = find(locations.get(), idEquals(dataCenter.location().getId()));
|
||||||
|
|
||||||
|
float size = 0f;
|
||||||
|
List<Volume> volumes = Lists.newArrayList();
|
||||||
|
List<Storage> storages = server.storages();
|
||||||
|
if (storages != null)
|
||||||
|
for (Storage storage : storages) {
|
||||||
|
size += storage.size();
|
||||||
|
volumes.add(fnVolume.apply(storage));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build hardware
|
||||||
|
String id = String.format("cpu=%d,ram=%d,disk=%.0f", server.cores(), server.ram(), size);
|
||||||
|
Hardware hardware = new HardwareBuilder()
|
||||||
|
.ids(id)
|
||||||
|
.name(id)
|
||||||
|
.ram(server.ram())
|
||||||
|
.processor(new Processor(server.cores(), 1d))
|
||||||
|
.hypervisor("kvm")
|
||||||
|
.volumes(volumes)
|
||||||
|
.location(location)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Collect ips
|
||||||
|
List<String> addresses = fnCollectIps.apply(server.nics());
|
||||||
|
|
||||||
|
// Build node
|
||||||
|
NodeMetadataBuilder nodeBuilder = new NodeMetadataBuilder();
|
||||||
|
nodeBuilder.ids(server.id())
|
||||||
|
.group(groupNamingConvention.extractGroup(server.name()))
|
||||||
|
.hostname(server.hostname())
|
||||||
|
.name(server.name())
|
||||||
|
.backendStatus(server.state().toString())
|
||||||
|
.status(mapStatus(server.status()))
|
||||||
|
.hardware(hardware)
|
||||||
|
.operatingSystem(mapOsType(server.osType()))
|
||||||
|
.location(location)
|
||||||
|
.privateAddresses(Iterables.filter(addresses, IsPrivateIPAddress.INSTANCE))
|
||||||
|
.publicAddresses(Iterables.filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
|
||||||
|
|
||||||
|
return nodeBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
static NodeMetadata.Status mapStatus(Server.Status status) {
|
||||||
|
if (status == null)
|
||||||
|
return NodeMetadata.Status.UNRECOGNIZED;
|
||||||
|
switch (status) {
|
||||||
|
case SHUTDOWN:
|
||||||
|
case SHUTOFF:
|
||||||
|
case PAUSED:
|
||||||
|
return NodeMetadata.Status.SUSPENDED;
|
||||||
|
case RUNNING:
|
||||||
|
return NodeMetadata.Status.RUNNING;
|
||||||
|
case BLOCKED:
|
||||||
|
return NodeMetadata.Status.PENDING;
|
||||||
|
case CRASHED:
|
||||||
|
return NodeMetadata.Status.ERROR;
|
||||||
|
default:
|
||||||
|
return NodeMetadata.Status.UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static OperatingSystem mapOsType(OsType osType) {
|
||||||
|
if (osType != null)
|
||||||
|
switch (osType) {
|
||||||
|
case WINDOWS:
|
||||||
|
return OperatingSystem.builder()
|
||||||
|
.description(OsFamily.WINDOWS.value())
|
||||||
|
.family(OsFamily.WINDOWS)
|
||||||
|
.build();
|
||||||
|
case LINUX:
|
||||||
|
return OperatingSystem.builder()
|
||||||
|
.description(OsFamily.LINUX.value())
|
||||||
|
.family(OsFamily.LINUX)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
return OperatingSystem.builder()
|
||||||
|
.description(OsFamily.UNRECOGNIZED.value())
|
||||||
|
.family(OsFamily.UNRECOGNIZED)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.compute.function;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.Volume;
|
||||||
|
import org.jclouds.compute.domain.VolumeBuilder;
|
||||||
|
import org.jclouds.profitbricks.domain.Storage;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
public class StorageToVolume implements Function<Storage, Volume> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Volume apply(Storage storage) {
|
||||||
|
checkNotNull(storage, "Null storage");
|
||||||
|
|
||||||
|
String device = "";
|
||||||
|
if (storage.deviceNumber() != null)
|
||||||
|
device = storage.deviceNumber().toString();
|
||||||
|
|
||||||
|
return new VolumeBuilder()
|
||||||
|
.id(storage.id())
|
||||||
|
.size(storage.size())
|
||||||
|
.bootDevice(storage.bootDevice())
|
||||||
|
.device(device)
|
||||||
|
.durable(true)
|
||||||
|
.type(Volume.Type.LOCAL)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* 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.compute.strategy;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.find;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||||
|
import static org.jclouds.profitbricks.config.ProfitBricksComputeProperties.POLL_PREDICATE_DATACENTER;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.config.CustomizationResponse;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.compute.functions.GroupNamingConvention;
|
||||||
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
|
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||||
|
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
|
||||||
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.Location;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to find a valid datacenter in the configured location where the
|
||||||
|
* servers will be deployed. If no datacenter is found, one will be created.
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
@Singleton
|
||||||
|
public class AssignDataCenterToTemplate extends CreateNodesWithGroupEncodedIntoNameThenAddToSet {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
private final ProfitBricksApi api;
|
||||||
|
private final Predicate<String> waitDcUntilAvailable;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected AssignDataCenterToTemplate(
|
||||||
|
CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy,
|
||||||
|
ListNodesStrategy listNodesStrategy,
|
||||||
|
GroupNamingConvention.Factory namingConvention,
|
||||||
|
@Named(PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
|
||||||
|
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
|
||||||
|
ProfitBricksApi api, @Named(POLL_PREDICATE_DATACENTER) Predicate<String> waitDcUntilAvailable) {
|
||||||
|
super(addNodeWithGroupStrategy, listNodesStrategy, namingConvention, userExecutor,
|
||||||
|
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
|
||||||
|
this.api = api;
|
||||||
|
this.waitDcUntilAvailable = waitDcUntilAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<?, ListenableFuture<Void>> execute(String group, int count, final Template template,
|
||||||
|
Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes,
|
||||||
|
Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
|
||||||
|
|
||||||
|
logger.info(">> looking for a datacenter in %s", template.getLocation().getId());
|
||||||
|
|
||||||
|
// Try to find an existing datacenter in the selected location
|
||||||
|
DataCenter dataCenter = find(api.dataCenterApi().getAllDataCenters(), new Predicate<DataCenter>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(DataCenter input) {
|
||||||
|
// The location field is not populated when getting the list of datacenters
|
||||||
|
DataCenter details = api.dataCenterApi().getDataCenter(input.id());
|
||||||
|
return details != null && template.getLocation().getId().equals(details.location().getId());
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
if (dataCenter == null) {
|
||||||
|
String name = namingConvention.create().sharedNameForGroup(group);
|
||||||
|
logger.info(">> no datacenter was found. Creating a new one named %s in %s...", name, template.getLocation()
|
||||||
|
.getId());
|
||||||
|
dataCenter = api.dataCenterApi().createDataCenter(
|
||||||
|
DataCenter.Request.creatingPayload(name, Location.fromId(template.getLocation().getId())));
|
||||||
|
waitDcUntilAvailable.apply(dataCenter.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.execute(group, count, new TemplateWithDataCenter(template, dataCenter), goodNodes, badNodes,
|
||||||
|
customizationResponses);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* 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.compute.strategy;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends the default {@link Template} object to provide the {@link DataCenter}
|
||||||
|
* where the nodes must be created.
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
public class TemplateWithDataCenter implements Template {
|
||||||
|
|
||||||
|
private final Template delegate;
|
||||||
|
|
||||||
|
private final DataCenter dataCenter;
|
||||||
|
|
||||||
|
// For internal use only
|
||||||
|
TemplateWithDataCenter(Template delegate, DataCenter dataCenter) {
|
||||||
|
this.delegate = checkNotNull(delegate, "delegate cannot be null");
|
||||||
|
this.dataCenter = checkNotNull(dataCenter, "dataCenter cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataCenter getDataCenter() {
|
||||||
|
return dataCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Template clone() {
|
||||||
|
return new TemplateWithDataCenter(delegate.clone(), dataCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Hardware getHardware() {
|
||||||
|
return delegate.getHardware();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image getImage() {
|
||||||
|
return delegate.getImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return delegate.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateOptions getOptions() {
|
||||||
|
return delegate.getOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((dataCenter == null) ? 0 : dataCenter.hashCode());
|
||||||
|
result = prime * result + ((delegate == null) ? 0 : delegate.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
TemplateWithDataCenter other = (TemplateWithDataCenter) obj;
|
||||||
|
if (dataCenter == null) {
|
||||||
|
if (other.dataCenter != null)
|
||||||
|
return false;
|
||||||
|
} else if (!dataCenter.equals(other.dataCenter))
|
||||||
|
return false;
|
||||||
|
if (delegate == null) {
|
||||||
|
if (other.delegate != null)
|
||||||
|
return false;
|
||||||
|
} else if (!delegate.equals(other.delegate))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return delegate.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.config;
|
||||||
|
|
||||||
|
public class ProfitBricksComputeProperties {
|
||||||
|
|
||||||
|
public static final String POLL_PREDICATE_DATACENTER = "jclouds.profitbricks.predicate.datacenter";
|
||||||
|
public static final String POLL_PREDICATE_SNAPSHOT = "jclouds.profitbricks.predicate.snapshot";
|
||||||
|
|
||||||
|
public static final String TIMEOUT_DATACENTER_AVAILABLE = "jclouds.profitbricks.timeout.datacenter-available";
|
||||||
|
public static final String POLL_INITIAL_PERIOD = "jclouds.profitbricks.poll-status.initial-period";
|
||||||
|
public static final String POLL_MAX_PERIOD = "jclouds.profitbricks.poll-status.poll.max-period";
|
||||||
|
|
||||||
|
private ProfitBricksComputeProperties() {
|
||||||
|
throw new AssertionError("Intentionally unimplemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.config;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpCommandExecutorService;
|
||||||
|
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||||
|
import org.jclouds.profitbricks.handlers.ProfitBricksHttpErrorHandler;
|
||||||
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
|
import org.jclouds.http.annotation.ClientError;
|
||||||
|
import org.jclouds.http.annotation.Redirection;
|
||||||
|
import org.jclouds.http.annotation.ServerError;
|
||||||
|
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
|
||||||
|
import org.jclouds.http.config.SSLModule;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.profitbricks.domain.ServiceFault;
|
||||||
|
import org.jclouds.profitbricks.http.ResponseStatusFromPayloadHttpCommandExecutorService;
|
||||||
|
import org.jclouds.profitbricks.http.parser.ServiceFaultResponseHandler;
|
||||||
|
import org.jclouds.rest.ConfiguresHttpApi;
|
||||||
|
import org.jclouds.rest.config.HttpApiModule;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the ProfitBricks connection.
|
||||||
|
*/
|
||||||
|
@ConfiguresHttpApi
|
||||||
|
public class ProfitBricksHttpApiModule extends HttpApiModule<ProfitBricksApi> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void bindErrorHandlers() {
|
||||||
|
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ProfitBricksHttpErrorHandler.class);
|
||||||
|
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ProfitBricksHttpErrorHandler.class);
|
||||||
|
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ProfitBricksHttpErrorHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfiguresHttpCommandExecutorService
|
||||||
|
public static class ProfitBricksHttpCommandExecutorServiceModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.common.base.Enums;
|
||||||
|
|
||||||
|
public enum AvailabilityZone {
|
||||||
|
|
||||||
|
AUTO, ZONE_1, ZONE_2, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return name();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AvailabilityZone fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(AvailabilityZone.class, v).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkInvalidChars;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class DataCenter {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
public abstract int version();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract ProvisioningState state();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Location location();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Server> servers();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Storage> storages();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_DataCenter.Builder()
|
||||||
|
.servers(ImmutableList.<Server>of())
|
||||||
|
.storages(ImmutableList.<Storage>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder version(int version);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
public abstract Builder location(Location location);
|
||||||
|
|
||||||
|
public abstract Builder servers(List<Server> servers);
|
||||||
|
|
||||||
|
public abstract Builder storages(List<Storage> storages);
|
||||||
|
|
||||||
|
abstract DataCenter autoBuild();
|
||||||
|
|
||||||
|
public DataCenter build(){
|
||||||
|
DataCenter built = autoBuild();
|
||||||
|
return built.toBuilder()
|
||||||
|
.servers(ImmutableList.copyOf(built.servers()))
|
||||||
|
.storages(ImmutableList.copyOf(built.storages()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static CreatePayload creatingPayload(String name, Location location) {
|
||||||
|
CreatePayload payload = new AutoValue_DataCenter_Request_CreatePayload(name, location);
|
||||||
|
checkInvalidChars(payload.name());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdatePayload updatingPayload(String id, String name) {
|
||||||
|
UpdatePayload payload = new AutoValue_DataCenter_Request_UpdatePayload(id, name);
|
||||||
|
checkInvalidChars(payload.name());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class CreatePayload {
|
||||||
|
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
public abstract Location location();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class UpdatePayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Drive {
|
||||||
|
|
||||||
|
public abstract static class Request {
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class AddRomDriveToServerPayload {
|
||||||
|
|
||||||
|
public abstract String serverId();
|
||||||
|
|
||||||
|
public abstract String imageId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String deviceNumber();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Drive_Request_AddRomDriveToServerPayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder serverId(String serverId);
|
||||||
|
|
||||||
|
public abstract Builder imageId(String imageId);
|
||||||
|
|
||||||
|
public abstract Builder deviceNumber(String deviceNumber);
|
||||||
|
|
||||||
|
public abstract AddRomDriveToServerPayload build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,188 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkIcmp;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkIp;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkMacAddress;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkPortRange;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Firewall {
|
||||||
|
|
||||||
|
public enum Protocol {
|
||||||
|
|
||||||
|
TCP, UDP, ICMP, ANY, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static Protocol fromValue(String value) {
|
||||||
|
return Enums.getIfPresent(Protocol.class, value).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String nicId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean active();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract ProvisioningState state();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Rule> rules();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Firewall.Builder()
|
||||||
|
.rules(ImmutableList.<Rule>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder nicId(String nicId);
|
||||||
|
|
||||||
|
public abstract Builder active(Boolean active);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
public abstract Builder rules(List<Rule> rules);
|
||||||
|
|
||||||
|
abstract Firewall autoBuild();
|
||||||
|
|
||||||
|
public Firewall build(){
|
||||||
|
Firewall built = autoBuild();
|
||||||
|
|
||||||
|
return built.toBuilder()
|
||||||
|
.rules(ImmutableList.copyOf(built.rules()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static AddRulePayload createAddRulePayload(String nicId, List<Rule> rules) {
|
||||||
|
return new AutoValue_Firewall_Request_AddRulePayload(nicId, ImmutableList.copyOf(rules));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class AddRulePayload {
|
||||||
|
|
||||||
|
public abstract String nicId();
|
||||||
|
|
||||||
|
public abstract List<Rule> rules();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class Rule {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer portRangeEnd();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer portRangeStart();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Protocol protocol();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String sourceIp();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String sourceMac();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String targetIp();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer icmpCode();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer icmpType();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Firewall_Rule.Builder()
|
||||||
|
.protocol(Protocol.ANY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new AutoValue_Firewall_Rule.Builder(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder portRangeEnd(Integer portRangeEnd);
|
||||||
|
|
||||||
|
public abstract Builder portRangeStart(Integer portRangeStart);
|
||||||
|
|
||||||
|
public abstract Builder protocol(Protocol protocol);
|
||||||
|
|
||||||
|
public abstract Builder sourceIp(String sourceIp);
|
||||||
|
|
||||||
|
public abstract Builder sourceMac(String sourceMac);
|
||||||
|
|
||||||
|
public abstract Builder targetIp(String targetIp);
|
||||||
|
|
||||||
|
public abstract Builder icmpCode(Integer icmpCode);
|
||||||
|
|
||||||
|
public abstract Builder icmpType(Integer icmpType);
|
||||||
|
|
||||||
|
abstract Rule autoBuild();
|
||||||
|
|
||||||
|
public Rule build() {
|
||||||
|
Rule rule = autoBuild();
|
||||||
|
if (rule.sourceIp() != null)
|
||||||
|
checkIp(rule.sourceIp());
|
||||||
|
if (rule.targetIp() != null)
|
||||||
|
checkIp(rule.targetIp());
|
||||||
|
if (rule.sourceMac() != null)
|
||||||
|
checkMacAddress(rule.sourceMac());
|
||||||
|
checkPortRange(rule.portRangeStart(), rule.portRangeEnd(), rule.protocol());
|
||||||
|
checkIcmp(rule.icmpType(), rule.icmpCode(), rule.protocol());
|
||||||
|
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Image implements Provisionable {
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
|
||||||
|
HDD, CDROM, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static Type fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(Type.class, v).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
public abstract float size(); // MB
|
||||||
|
|
||||||
|
public abstract Location location();
|
||||||
|
|
||||||
|
public abstract OsType osType();
|
||||||
|
|
||||||
|
public abstract Type type();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isPublic();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isWriteable();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isBootable();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotUnPlug();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Image.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder size(float size);
|
||||||
|
|
||||||
|
public abstract Builder location(Location location);
|
||||||
|
|
||||||
|
public abstract Builder osType(OsType osType);
|
||||||
|
|
||||||
|
public abstract Builder type(Type type);
|
||||||
|
|
||||||
|
public abstract Builder isPublic(Boolean isPublic);
|
||||||
|
|
||||||
|
public abstract Builder isWriteable(Boolean isWriteable);
|
||||||
|
|
||||||
|
public abstract Builder isBootable(Boolean isBootable);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotPlug(Boolean isCpuHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotUnPlug(Boolean isCpuHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotPlug(Boolean isRamHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotUnPlug(Boolean isRamHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotPlug(Boolean isNicHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotUnPlug(Boolean isNicHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotPlug(Boolean isDiscVirtioHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotUnPlug(Boolean isDiscVirtioHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Image build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkIp;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkIps;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class IpBlock {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
public abstract Location location();
|
||||||
|
|
||||||
|
public abstract List<PublicIp> publicIps();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<String> ips();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_IpBlock.Builder()
|
||||||
|
.publicIps(ImmutableList.<PublicIp>of())
|
||||||
|
.ips(ImmutableList.<String>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder location(Location location);
|
||||||
|
|
||||||
|
public abstract Builder publicIps(List<PublicIp> publicIps);
|
||||||
|
|
||||||
|
public abstract Builder ips(List<String> ips);
|
||||||
|
|
||||||
|
abstract IpBlock autoBuild();
|
||||||
|
|
||||||
|
public IpBlock build() {
|
||||||
|
IpBlock ipBlock = autoBuild();
|
||||||
|
checkIps(ipBlock.ips());
|
||||||
|
|
||||||
|
return ipBlock.toBuilder()
|
||||||
|
.publicIps(ImmutableList.copyOf(ipBlock.publicIps()))
|
||||||
|
.ips(ImmutableList.copyOf(ipBlock.ips()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class PublicIp {
|
||||||
|
|
||||||
|
public abstract String ip();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String nicId();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_IpBlock_PublicIp.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder ip(String ip);
|
||||||
|
|
||||||
|
public abstract Builder nicId(String nicId);
|
||||||
|
|
||||||
|
abstract PublicIp autoBuild();
|
||||||
|
|
||||||
|
public PublicIp build() {
|
||||||
|
PublicIp publicIp = autoBuild();
|
||||||
|
checkIp(publicIp.ip());
|
||||||
|
|
||||||
|
return publicIp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,257 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkIp;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkLanId;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class LoadBalancer {
|
||||||
|
|
||||||
|
public enum Algorithm {
|
||||||
|
|
||||||
|
ROUND_ROBIN, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static Algorithm
|
||||||
|
fromValue(String value) {
|
||||||
|
return Enums.getIfPresent(Algorithm.class, value).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Algorithm algorithm();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract DataCenter dataCenter();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean internetAccess();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String ip();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer lanId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract ProvisioningState state();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Date creationTime();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Date lastModificationTime();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Server> balancedServers();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Firewall> firewalls();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_LoadBalancer.Builder()
|
||||||
|
.balancedServers(ImmutableList.<Server>of())
|
||||||
|
.firewalls(ImmutableList.<Firewall>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder algorithm(Algorithm algorithm);
|
||||||
|
|
||||||
|
public abstract Builder dataCenter(DataCenter dataCenter);
|
||||||
|
|
||||||
|
public abstract Builder internetAccess(Boolean internetAccess);
|
||||||
|
|
||||||
|
public abstract Builder ip(String ip);
|
||||||
|
|
||||||
|
public abstract Builder lanId(Integer lanId);
|
||||||
|
|
||||||
|
public abstract Builder creationTime(Date creationTime);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
public abstract Builder lastModificationTime(Date lastModificationTime);
|
||||||
|
|
||||||
|
public abstract Builder balancedServers(List<Server> balancedServers);
|
||||||
|
|
||||||
|
public abstract Builder firewalls(List<Firewall> firewalls);
|
||||||
|
|
||||||
|
abstract LoadBalancer autoBuild();
|
||||||
|
|
||||||
|
public LoadBalancer build() {
|
||||||
|
LoadBalancer loadBalancer = autoBuild();
|
||||||
|
if (loadBalancer.ip() != null)
|
||||||
|
checkIp(loadBalancer.ip());
|
||||||
|
if (loadBalancer.lanId() != null)
|
||||||
|
checkLanId(loadBalancer.lanId());
|
||||||
|
|
||||||
|
return loadBalancer.toBuilder()
|
||||||
|
.balancedServers(ImmutableList.copyOf(loadBalancer.balancedServers()))
|
||||||
|
.firewalls(ImmutableList.copyOf(loadBalancer.firewalls()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static CreatePayload.Builder creatingBuilder() {
|
||||||
|
return new AutoValue_LoadBalancer_Request_CreatePayload.Builder()
|
||||||
|
.serverIds(ImmutableList.<String>of())
|
||||||
|
.algorithm(Algorithm.ROUND_ROBIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdatePayload.Builder updatingBuilder() {
|
||||||
|
return new AutoValue_LoadBalancer_Request_UpdatePayload.Builder()
|
||||||
|
.algorithm(Algorithm.ROUND_ROBIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RegisterPayload createRegisteringPaylod(String loadBalancerId, List<String> serverIds) {
|
||||||
|
return new AutoValue_LoadBalancer_Request_RegisterPayload(loadBalancerId, ImmutableList.copyOf(serverIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeregisterPayload createDeregisteringPayload(String loadBalancerId, List<String> serverIds) {
|
||||||
|
return new AutoValue_LoadBalancer_Request_DeregisterPayload(loadBalancerId, ImmutableList.copyOf(serverIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class CreatePayload {
|
||||||
|
|
||||||
|
public abstract String dataCenterId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
public abstract Algorithm algorithm();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String ip();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer lanId();
|
||||||
|
|
||||||
|
public abstract List<String> serverIds();
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder dataCenterId(String dataCenterId);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder algorithm(Algorithm algorithm);
|
||||||
|
|
||||||
|
public abstract Builder ip(String ip);
|
||||||
|
|
||||||
|
public abstract Builder lanId(Integer lanId);
|
||||||
|
|
||||||
|
public abstract Builder serverIds(List<String> serverIds);
|
||||||
|
|
||||||
|
abstract CreatePayload autoBuild();
|
||||||
|
|
||||||
|
public CreatePayload build() {
|
||||||
|
CreatePayload payload = autoBuild();
|
||||||
|
if (payload.ip() != null)
|
||||||
|
checkIp(payload.ip());
|
||||||
|
if (payload.lanId() != null)
|
||||||
|
checkLanId(payload.lanId());
|
||||||
|
|
||||||
|
return payload.toBuilder()
|
||||||
|
.serverIds(ImmutableList.copyOf(payload.serverIds()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class RegisterPayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
public abstract List<String> serverIds();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class DeregisterPayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
public abstract List<String> serverIds();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class UpdatePayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
public abstract Algorithm algorithm();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String ip();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder algorithm(Algorithm algorithm);
|
||||||
|
|
||||||
|
public abstract Builder ip(String ip);
|
||||||
|
|
||||||
|
abstract UpdatePayload autoBuild();
|
||||||
|
|
||||||
|
public UpdatePayload build() {
|
||||||
|
UpdatePayload payload = autoBuild();
|
||||||
|
if (payload.ip() != null)
|
||||||
|
checkIp(payload.ip());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
|
||||||
|
public enum Location {
|
||||||
|
|
||||||
|
DE_FKB("de/fkb", "Germany, Karlsruhe"),
|
||||||
|
DE_FRA("de/fra", "Germany, Frankfurt (M)"),
|
||||||
|
US_LAS("us/las", "USA, Las Vegas"),
|
||||||
|
US_LASDEV("us/lasdev", "USA Developer cluster"),
|
||||||
|
UNRECOGNIZED("unrecognized", "Unrecognized location");
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
Location(String id, String description) {
|
||||||
|
this.id = id;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(Location.class, v).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location fromId(String id) {
|
||||||
|
for (Location location : values())
|
||||||
|
if (location.id.equals(id))
|
||||||
|
return location;
|
||||||
|
return UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,248 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkIp;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkIps;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkLanId;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkMacAddress;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Nic {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String dataCenterId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer lanId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean internetAccess();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String serverId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<String> ips();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String macAddress();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Firewall firewall();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean dhcpActive();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String gatewayIp();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract ProvisioningState state();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Nic.Builder()
|
||||||
|
.ips(ImmutableList.<String>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder dataCenterId(String dataCenterId);
|
||||||
|
|
||||||
|
public abstract Builder lanId(Integer lanId);
|
||||||
|
|
||||||
|
public abstract Builder internetAccess(Boolean internetAccess);
|
||||||
|
|
||||||
|
public abstract Builder serverId(String serverId);
|
||||||
|
|
||||||
|
public abstract Builder ips(List<String> ips);
|
||||||
|
|
||||||
|
public abstract Builder macAddress(String macAddress);
|
||||||
|
|
||||||
|
public abstract Builder firewall(Firewall firewall);
|
||||||
|
|
||||||
|
public abstract Builder dhcpActive(Boolean dhcpActive);
|
||||||
|
|
||||||
|
public abstract Builder gatewayIp(String gatewayIp);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
abstract Nic autoBuild();
|
||||||
|
|
||||||
|
public Nic build() {
|
||||||
|
Nic nic = autoBuild();
|
||||||
|
if (nic.ips() != null)
|
||||||
|
checkIps(nic.ips());
|
||||||
|
if (nic.gatewayIp() != null)
|
||||||
|
checkIp(nic.gatewayIp());
|
||||||
|
if (nic.lanId() != null)
|
||||||
|
checkLanId(nic.lanId());
|
||||||
|
if (nic.macAddress() != null)
|
||||||
|
checkMacAddress(nic.macAddress());
|
||||||
|
|
||||||
|
return nic.toBuilder()
|
||||||
|
.ips(ImmutableList.copyOf(nic.ips()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static CreatePayload.Builder creatingBuilder() {
|
||||||
|
return new AutoValue_Nic_Request_CreatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdatePayload.Builder updatingBuilder() {
|
||||||
|
return new AutoValue_Nic_Request_UpdatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SetInternetAccessPayload.Builder setInternetAccessBuilder() {
|
||||||
|
return new AutoValue_Nic_Request_SetInternetAccessPayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class CreatePayload {
|
||||||
|
|
||||||
|
public abstract String serverId();
|
||||||
|
|
||||||
|
public abstract int lanId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String ip();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean dhcpActive();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder serverId(String serverId);
|
||||||
|
|
||||||
|
public abstract Builder lanId(int lanId);
|
||||||
|
|
||||||
|
public abstract Builder ip(String ip);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder dhcpActive(Boolean dhcpActive);
|
||||||
|
|
||||||
|
abstract CreatePayload autoBuild();
|
||||||
|
|
||||||
|
public CreatePayload build() {
|
||||||
|
CreatePayload payload = autoBuild();
|
||||||
|
if (payload.ip() != null)
|
||||||
|
checkIp(payload.ip());
|
||||||
|
checkLanId(payload.lanId());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class UpdatePayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String ip();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean dhcpActive();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer lanId();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder ip(String ip);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder dhcpActive(Boolean dhcpActive);
|
||||||
|
|
||||||
|
public abstract Builder lanId(Integer lanId);
|
||||||
|
|
||||||
|
abstract UpdatePayload autoBuild();
|
||||||
|
|
||||||
|
public UpdatePayload build() {
|
||||||
|
UpdatePayload payload = autoBuild();
|
||||||
|
if (payload.ip() != null)
|
||||||
|
checkIp(payload.ip());
|
||||||
|
if (payload.lanId() != null)
|
||||||
|
checkLanId(payload.lanId());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class SetInternetAccessPayload {
|
||||||
|
|
||||||
|
public abstract String dataCenterId();
|
||||||
|
|
||||||
|
public abstract int lanId();
|
||||||
|
|
||||||
|
public abstract boolean internetAccess();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder dataCenterId(String dataCenterId);
|
||||||
|
|
||||||
|
public abstract Builder lanId(int lanId);
|
||||||
|
|
||||||
|
public abstract Builder internetAccess(boolean internetAccess);
|
||||||
|
|
||||||
|
public abstract SetInternetAccessPayload build();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* 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.common.base.Enums;
|
||||||
|
|
||||||
|
public enum OsType {
|
||||||
|
|
||||||
|
WINDOWS, LINUX, OTHER, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static OsType fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(OsType.class, v).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker interface for {@link org.jclouds.profitbricks.domain.Image} and
|
||||||
|
* {@link org.jclouds.profitbricks.domain.Snapshot}
|
||||||
|
*/
|
||||||
|
public interface Provisionable {
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
|
||||||
|
IMAGE, SNAPSHOT;
|
||||||
|
|
||||||
|
public static Type fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(Type.class, v).or(IMAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* 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.common.base.Enums;
|
||||||
|
|
||||||
|
public enum ProvisioningState {
|
||||||
|
|
||||||
|
INACTIVE, INPROCESS, AVAILABLE, DELETED, ERROR, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static ProvisioningState fromValue(String value) {
|
||||||
|
return Enums.getIfPresent(ProvisioningState.class, value).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,410 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkCores;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkRam;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Server {
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
NOSTATE, RUNNING, BLOCKED, PAUSED, SHUTDOWN, SHUTOFF, CRASHED, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return name();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Status fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(Status.class, v).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract DataCenter dataCenter();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer cores();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer ram();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean hasInternetAccess();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract ProvisioningState state();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Status status();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract OsType osType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract AvailabilityZone availabilityZone();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Date creationTime();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Date lastModificationTime();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Storage> storages();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract List<Nic> nics();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String balancedNicId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean loadBalanced();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String hostname(); // Non-profitbricks property; Added to hold hostname parsed from image temporarily
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Server.Builder()
|
||||||
|
.storages(ImmutableList.<Storage>of())
|
||||||
|
.nics(ImmutableList.<Nic>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder dataCenter(DataCenter dataCenter);
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder cores(Integer cores);
|
||||||
|
|
||||||
|
public abstract Builder ram(Integer ram);
|
||||||
|
|
||||||
|
public abstract Builder hasInternetAccess(Boolean internetAccess);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
public abstract Builder status(Status status);
|
||||||
|
|
||||||
|
public abstract Builder osType(OsType osType);
|
||||||
|
|
||||||
|
public abstract Builder availabilityZone(AvailabilityZone availabilityZone);
|
||||||
|
|
||||||
|
public abstract Builder creationTime(Date creationTime);
|
||||||
|
|
||||||
|
public abstract Builder lastModificationTime(Date lastModificationTime);
|
||||||
|
|
||||||
|
public abstract Builder storages(List<Storage> storages);
|
||||||
|
|
||||||
|
public abstract Builder nics(List<Nic> nics);
|
||||||
|
|
||||||
|
public abstract Builder balancedNicId(String balancedNicIds);
|
||||||
|
|
||||||
|
public abstract Builder loadBalanced(Boolean isLoadBalanced);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotPlug(Boolean isCpuHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotUnPlug(Boolean isCpuHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotPlug(Boolean isRamHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotUnPlug(Boolean isRamHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotPlug(Boolean isNicHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotUnPlug(Boolean isNicHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotPlug(Boolean isDiscVirtioHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotUnPlug(Boolean isDiscVirtioHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder hostname(String hostname);
|
||||||
|
|
||||||
|
abstract Server autoBuild();
|
||||||
|
|
||||||
|
public Server build() {
|
||||||
|
Server server = autoBuild();
|
||||||
|
if (server.cores() != null)
|
||||||
|
checkCores(server.cores());
|
||||||
|
if (server.ram() != null)
|
||||||
|
checkRam(server.ram(), server.isRamHotUnPlug());
|
||||||
|
return server.toBuilder()
|
||||||
|
.storages(ImmutableList.copyOf(server.storages()))
|
||||||
|
.nics(ImmutableList.copyOf(server.nics()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static CreatePayload.Builder creatingBuilder() {
|
||||||
|
return new AutoValue_Server_Request_CreatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdatePayload.Builder updatingBuilder() {
|
||||||
|
return new AutoValue_Server_Request_UpdatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class CreatePayload {
|
||||||
|
|
||||||
|
public abstract int cores();
|
||||||
|
|
||||||
|
public abstract int ram();
|
||||||
|
|
||||||
|
public abstract String dataCenterId();
|
||||||
|
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String bootFromStorageId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String bootFromImageId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer lanId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean hasInternetAccess();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract AvailabilityZone availabilityZone();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract OsType osType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotUnPlug();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder cores(int cores);
|
||||||
|
|
||||||
|
public abstract Builder ram(int ram);
|
||||||
|
|
||||||
|
public abstract Builder dataCenterId(String dataCenterId);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder bootFromStorageId(String bootFromStorageId);
|
||||||
|
|
||||||
|
public abstract Builder bootFromImageId(String bootFromImageId);
|
||||||
|
|
||||||
|
public abstract Builder lanId(Integer lanId);
|
||||||
|
|
||||||
|
public abstract Builder hasInternetAccess(Boolean hasInternetAccess);
|
||||||
|
|
||||||
|
public abstract Builder availabilityZone(AvailabilityZone availabilityZone);
|
||||||
|
|
||||||
|
public abstract Builder osType(OsType osType);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotPlug(Boolean isCpuHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotUnPlug(Boolean isCpuHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotPlug(Boolean isRamHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotUnPlug(Boolean isRamHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotPlug(Boolean isNicHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotUnPlug(Boolean isNicHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotPlug(Boolean isDiscVirtioHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotUnPlug(Boolean isDiscVirtioHotUnPlug);
|
||||||
|
|
||||||
|
abstract CreatePayload autoBuild();
|
||||||
|
|
||||||
|
public CreatePayload build() {
|
||||||
|
CreatePayload payload = autoBuild();
|
||||||
|
checkCores(payload.cores());
|
||||||
|
checkRam(payload.ram(), payload.isRamHotUnPlug());
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class UpdatePayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer cores();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer ram();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String bootFromStorageId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String bootFromImageId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract AvailabilityZone availabilityZone();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract OsType osType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotUnPlug();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder cores(Integer cores);
|
||||||
|
|
||||||
|
public abstract Builder ram(Integer ram);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder bootFromStorageId(String bootFromStorageId);
|
||||||
|
|
||||||
|
public abstract Builder bootFromImageId(String bootFromImageId);
|
||||||
|
|
||||||
|
public abstract Builder availabilityZone(AvailabilityZone availabilityZone);
|
||||||
|
|
||||||
|
public abstract Builder osType(OsType osType);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotPlug(Boolean isCpuHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotUnPlug(Boolean isCpuHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotPlug(Boolean isRamHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotUnPlug(Boolean isRamHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotPlug(Boolean isNicHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotUnPlug(Boolean isNicHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotPlug(Boolean isDiscVirtioHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotUnPlug(Boolean isDiscVirtioHotUnPlug);
|
||||||
|
|
||||||
|
abstract UpdatePayload autoBuild();
|
||||||
|
|
||||||
|
public UpdatePayload build() {
|
||||||
|
UpdatePayload payload = autoBuild();
|
||||||
|
if (payload.cores() != null)
|
||||||
|
checkCores(payload.cores());
|
||||||
|
if (payload.ram() != null)
|
||||||
|
checkRam(payload.ram(), payload.isRamHotUnPlug());
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.domain;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class ServiceFault {
|
||||||
|
|
||||||
|
public enum FaultCode {
|
||||||
|
|
||||||
|
BAD_REQUEST,
|
||||||
|
UNEXPECTED,
|
||||||
|
UNAUTHORIZED,
|
||||||
|
RESOURCE_NOT_FOUND,
|
||||||
|
RESOURCE_DELETED,
|
||||||
|
PROVISIONING_IN_PROCESS,
|
||||||
|
PROVISIONING_NO_CHANGES,
|
||||||
|
OVER_LIMIT_SETTING,
|
||||||
|
SERVER_EXCEED_CAPACITY,
|
||||||
|
SERVICE_UNAVAILABLE,
|
||||||
|
UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static FaultCode fromValue(String v) {
|
||||||
|
return Enums.getIfPresent(FaultCode.class, v).or(UNRECOGNIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract FaultCode faultCode();
|
||||||
|
|
||||||
|
public abstract int httpCode();
|
||||||
|
|
||||||
|
public abstract String message();
|
||||||
|
|
||||||
|
public abstract int requestId();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_ServiceFault.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder faultCode(FaultCode faultCode);
|
||||||
|
|
||||||
|
public abstract Builder httpCode(int httpCode);
|
||||||
|
|
||||||
|
public abstract Builder message(String message);
|
||||||
|
|
||||||
|
public abstract Builder requestId(int requestId);
|
||||||
|
|
||||||
|
public abstract ServiceFault build();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,251 @@
|
||||||
|
/*
|
||||||
|
* 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 java.util.Date;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Snapshot implements Provisionable {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Float size();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Location location();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract OsType osType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isBootable();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String description();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Date creationTime();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Date lastModificationTime();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract ProvisioningState state();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotUnPlug();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_Snapshot.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder size(Float size);
|
||||||
|
|
||||||
|
public abstract Builder location(Location location);
|
||||||
|
|
||||||
|
public abstract Builder osType(OsType osType);
|
||||||
|
|
||||||
|
public abstract Builder isBootable(Boolean bootable);
|
||||||
|
|
||||||
|
public abstract Builder description(String description);
|
||||||
|
|
||||||
|
public abstract Builder creationTime(Date creationTime);
|
||||||
|
|
||||||
|
public abstract Builder lastModificationTime(Date lastModificationTime);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotPlug(Boolean isCpuHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotUnPlug(Boolean isCpuHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotPlug(Boolean isRamHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotUnPlug(Boolean isRamHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotPlug(Boolean isNicHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotUnPlug(Boolean isNicHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotPlug(Boolean isDiscVirtioHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotUnPlug(Boolean isDiscVirtioHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Snapshot build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static CreatePayload.Builder creatingBuilder() {
|
||||||
|
return new AutoValue_Snapshot_Request_CreatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdatePayload.Builder updatingBuilder() {
|
||||||
|
return new AutoValue_Snapshot_Request_UpdatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RollbackPayload createRollbackPayload(String snapshotId, String storageId) {
|
||||||
|
return new AutoValue_Snapshot_Request_RollbackPayload(snapshotId, storageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class CreatePayload {
|
||||||
|
|
||||||
|
public abstract String storageId();
|
||||||
|
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String description();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder storageId(String storageId);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder description(String description);
|
||||||
|
|
||||||
|
public abstract CreatePayload build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class UpdatePayload {
|
||||||
|
|
||||||
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String description();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract String name();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean bootable();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract OsType osType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isCpuHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isRamHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isNicHotUnPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotPlug();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDiscVirtioHotUnPlug();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String snapshotId);
|
||||||
|
|
||||||
|
public abstract Builder description(String description);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder bootable(Boolean bootable);
|
||||||
|
|
||||||
|
public abstract Builder osType(OsType osType);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotPlug(Boolean isCpuHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isCpuHotUnPlug(Boolean isCpuHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotPlug(Boolean isRamHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isRamHotUnPlug(Boolean isRamHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotPlug(Boolean isNicHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isNicHotUnPlug(Boolean isNicHotUnPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotPlug(Boolean isDiscVirtioHotPlug);
|
||||||
|
|
||||||
|
public abstract Builder isDiscVirtioHotUnPlug(Boolean isDiscVirtioHotUnPlug);
|
||||||
|
|
||||||
|
public abstract UpdatePayload build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class RollbackPayload {
|
||||||
|
|
||||||
|
public abstract String snapshotId();
|
||||||
|
|
||||||
|
public abstract String storageId();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,234 @@
|
||||||
|
/*
|
||||||
|
* 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 static org.jclouds.profitbricks.util.Preconditions.checkPassword;
|
||||||
|
import static org.jclouds.profitbricks.util.Preconditions.checkSize;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.google.common.base.Enums;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract class Storage {
|
||||||
|
|
||||||
|
public enum BusType {
|
||||||
|
|
||||||
|
IDE, SCSI, VIRTIO, UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static BusType fromValue(String value) {
|
||||||
|
return Enums.getIfPresent(BusType.class, value).or(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();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
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 Builder builder() {
|
||||||
|
return new AutoValue_Storage.Builder()
|
||||||
|
.serverIds(ImmutableList.<String>of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder size(float size);
|
||||||
|
|
||||||
|
public abstract Builder creationTime(Date creationTime);
|
||||||
|
|
||||||
|
public abstract Builder lastModificationTime(Date lastModificationTime);
|
||||||
|
|
||||||
|
public abstract Builder state(ProvisioningState state);
|
||||||
|
|
||||||
|
public abstract Builder serverIds(List<String> serverIds);
|
||||||
|
|
||||||
|
public abstract Builder bootDevice(Boolean bootDevice);
|
||||||
|
|
||||||
|
public abstract Builder busType(BusType busType);
|
||||||
|
|
||||||
|
public abstract Builder deviceNumber(Integer deviceNumber);
|
||||||
|
|
||||||
|
abstract Storage autoBuild();
|
||||||
|
|
||||||
|
public Storage build(){
|
||||||
|
Storage built = autoBuild();
|
||||||
|
return built.toBuilder()
|
||||||
|
.serverIds(ImmutableList.copyOf(built.serverIds()))
|
||||||
|
.autoBuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Request {
|
||||||
|
|
||||||
|
public static CreatePayload.Builder creatingBuilder() {
|
||||||
|
return new AutoValue_Storage_Request_CreatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpdatePayload.Builder updatingBuilder() {
|
||||||
|
return new AutoValue_Storage_Request_UpdatePayload.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConnectPayload.Builder connectingBuilder() {
|
||||||
|
return new AutoValue_Storage_Request_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 imagePassword();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder dataCenterId(String dataCenterId);
|
||||||
|
|
||||||
|
public abstract Builder size(float size);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder mountImageId(String mountImageId);
|
||||||
|
|
||||||
|
public abstract Builder imagePassword(String profitBricksImagePassword);
|
||||||
|
|
||||||
|
abstract CreatePayload autoBuild();
|
||||||
|
|
||||||
|
public CreatePayload build() {
|
||||||
|
CreatePayload payload = autoBuild();
|
||||||
|
if (payload.imagePassword() != null)
|
||||||
|
checkPassword(payload.imagePassword());
|
||||||
|
checkSize(payload.size());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder id(String id);
|
||||||
|
|
||||||
|
public abstract Builder size(Float size);
|
||||||
|
|
||||||
|
public abstract Builder name(String name);
|
||||||
|
|
||||||
|
public abstract Builder mountImageId(String mountImageId);
|
||||||
|
|
||||||
|
abstract UpdatePayload autoBuild();
|
||||||
|
|
||||||
|
public UpdatePayload build() {
|
||||||
|
UpdatePayload payload = autoBuild();
|
||||||
|
if (payload.size() != null)
|
||||||
|
checkSize(payload.size());
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoValue
|
||||||
|
public abstract static class ConnectPayload {
|
||||||
|
|
||||||
|
public abstract String storageId();
|
||||||
|
|
||||||
|
public abstract String serverId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract BusType busType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Integer deviceNumber();
|
||||||
|
|
||||||
|
@AutoValue.Builder
|
||||||
|
public abstract static class Builder {
|
||||||
|
|
||||||
|
public abstract Builder storageId(String storageId);
|
||||||
|
|
||||||
|
public abstract Builder serverId(String serverId);
|
||||||
|
|
||||||
|
public abstract Builder busType(BusType busType);
|
||||||
|
|
||||||
|
public abstract Builder deviceNumber(Integer deviceNumber);
|
||||||
|
|
||||||
|
public abstract ConnectPayload build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
/*
|
||||||
|
* 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.datacenter.CreateDataCenterRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.datacenter.UpdateDataCenterRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.datacenter.DataCenterInfoResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.datacenter.DataCenterListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.state.GetProvisioningStateResponseHandler;
|
||||||
|
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 DataCenterApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns a list of all Virtual Data Centers created by the user, including ID, name and version number.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:getall")
|
||||||
|
@Payload("<ws:getAllDataCenters/>")
|
||||||
|
@XMLResponseParser(DataCenterListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<DataCenter> getAllDataCenters();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:get")
|
||||||
|
@Payload("<ws:getDataCenter><dataCenterId>{id}</dataCenterId></ws:getDataCenter>")
|
||||||
|
@XMLResponseParser(DataCenterInfoResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
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.
|
||||||
|
* <p>
|
||||||
|
* @param identifier Data Center identifier
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:getstate")
|
||||||
|
@Payload("<ws:getDataCenterState><dataCenterId>{id}</dataCenterId></ws:getDataCenterState>")
|
||||||
|
@XMLResponseParser(GetProvisioningStateResponseHandler.class)
|
||||||
|
ProvisioningState getDataCenterState(@PayloadParam("id") String identifier);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and saves a new, empty Virtual Data Center. Returns its identifier for further reference.
|
||||||
|
* <p>
|
||||||
|
* <b>Note: </b>Data center names cannot start with or contain (@, /, \, |, ‘’, ‘)
|
||||||
|
* <p>
|
||||||
|
* @param createRequest VDC payload containing dataCenterName, region
|
||||||
|
* @return Response containing requestId, dataCenterId, version, and location
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:create")
|
||||||
|
@MapBinder(CreateDataCenterRequestBinder.class)
|
||||||
|
@XMLResponseParser(DataCenterInfoResponseHandler.class)
|
||||||
|
DataCenter createDataCenter(@PayloadParam("dataCenter") DataCenter.Request.CreatePayload createRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the information associated to an existing Virtual Data Center.
|
||||||
|
* <p>
|
||||||
|
* @param updateRequest VDC payload containing dataCenterId, and name
|
||||||
|
* @return Response containing requestId, dataCenterId, version
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:update")
|
||||||
|
@MapBinder(UpdateDataCenterRequestBinder.class)
|
||||||
|
@XMLResponseParser(DataCenterInfoResponseHandler.class)
|
||||||
|
DataCenter updateDataCenter(@PayloadParam("dataCenter") DataCenter.Request.UpdatePayload updateRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all components from an existing Virtual Data Center.
|
||||||
|
* <p>
|
||||||
|
* @param identifier Identifier of the virtual data center
|
||||||
|
* @return Response containing requestId, dataCenterId, version
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:clear")
|
||||||
|
@Payload("<ws:clearDataCenter><dataCenterId>{id}</dataCenterId></ws:clearDataCenter>")
|
||||||
|
@XMLResponseParser(DataCenterInfoResponseHandler.class)
|
||||||
|
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.
|
||||||
|
* <p>
|
||||||
|
* @param identifier Identifier of the virtual data center
|
||||||
|
* @return Returns a boolean indicating whether delete operation was made
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("datacenter:delete")
|
||||||
|
@Payload("<ws:deleteDataCenter><dataCenterId>{id}</dataCenterId></ws:deleteDataCenter>")
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean deleteDataCenter(@PayloadParam("id") String identifier);
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.features;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.binder.drive.AddRomDriveToServerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Drive;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.annotations.Payload;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface DrivesApi {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("drives:add")
|
||||||
|
@MapBinder(AddRomDriveToServerRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String addRomDriveToServer(@PayloadParam("payload") Drive.Request.AddRomDriveToServerPayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("drives:remove")
|
||||||
|
@Payload("<ws:removeRomDriveFromServer><imageId>{imageid}</imageId><serverId>{serverid}</serverId></ws:removeRomDriveFromServer>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String removeRomDriveFromServer(@PayloadParam("imageid") String imageid, @PayloadParam("serverid") String serverid);
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* 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.firewall.AddFirewallRuleToNicRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.firewall.FirewallBinder.ActivateFirewallRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.firewall.FirewallBinder.DeactivateFirewallRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.firewall.FirewallBinder.DeleteFirewallRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.firewall.FirewallBinder.RemoveFirewallRuleRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
|
||||||
|
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;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface FirewallApi {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:get")
|
||||||
|
@Payload("<ws:getFirewall><firewallId>{id}</firewallId></ws:getFirewall>")
|
||||||
|
@XMLResponseParser(FirewallResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
Firewall getFirewall(@PayloadParam("id") String identifier);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:getall")
|
||||||
|
@Payload("<ws:getAllFirewalls/>")
|
||||||
|
@XMLResponseParser(FirewallListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<Firewall> getAllFirewalls();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:addrule")
|
||||||
|
@MapBinder(AddFirewallRuleToNicRequestBinder.class)
|
||||||
|
@XMLResponseParser(FirewallResponseHandler.class)
|
||||||
|
Firewall addFirewallRuleToNic(@PayloadParam("firewall") Firewall.Request.AddRulePayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:removerule")
|
||||||
|
@MapBinder(RemoveFirewallRuleRequestBinder.class)
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean removeFirewallRules(@PayloadParam("ids") List<String> firewallRuleIds);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:activate")
|
||||||
|
@MapBinder(ActivateFirewallRequestBinder.class)
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean activateFirewall(@PayloadParam("ids") List<String> firewallIds);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:activate")
|
||||||
|
@MapBinder(DeactivateFirewallRequestBinder.class)
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean deactivateFirewall(@PayloadParam("ids") List<String> firewallIds);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("firewall:activate")
|
||||||
|
@MapBinder(DeleteFirewallRequestBinder.class)
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean deleteFirewall(@PayloadParam("ids") List<String> firewallIds);
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.features;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import org.jclouds.Fallbacks;
|
||||||
|
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.domain.Image;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.image.ImageInfoResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.image.ImageListResponseHandler;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.Payload;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface ImageApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Outputs a list of all HDD and/or CD-ROM/DVD images existing on or uploaded to the ProfitBricks FTP server.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("image:getall")
|
||||||
|
@Payload("<ws:getAllImages/>")
|
||||||
|
@XMLResponseParser(ImageListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<Image> getAllImages();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param identifier Image Id
|
||||||
|
* @return Returns information about a HDD or CD-ROM/DVD (ISO) image.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("image:get")
|
||||||
|
@Payload("<ws:getImage><imageId>{id}</imageId></ws:getImage>")
|
||||||
|
@XMLResponseParser(ImageInfoResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
Image getImage(@PayloadParam("id") String identifier);
|
||||||
|
}
|
|
@ -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.features;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.domain.IpBlock;
|
||||||
|
import org.jclouds.profitbricks.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.ipblock.IpBlockListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.ipblock.IpBlockResponseHandler;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.Payload;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface IpBlockApi {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("publicipblock:get")
|
||||||
|
@Payload("<ws:getPublicIpBlock><blockId>{id}</blockId></ws:getPublicIpBlock>")
|
||||||
|
@XMLResponseParser(IpBlockResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
IpBlock getIpBlock(@PayloadParam("id") String identifier);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("publicipblock:getall")
|
||||||
|
@Payload("<ws:getAllPublicIpBlocks />")
|
||||||
|
@XMLResponseParser(IpBlockListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<IpBlock> getAllIpBlock();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("publicipblock:reserve")
|
||||||
|
@Payload("<ws:reservePublicIpBlock><request><blockSize>{blockSize}</blockSize><location>{location}</location></request></ws:reservePublicIpBlock>")
|
||||||
|
@XMLResponseParser(IpBlockResponseHandler.class)
|
||||||
|
IpBlock reservePublicIpBlock(@PayloadParam("blockSize") int blockSize, @PayloadParam("location") Location location);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("publicipblock:addip")
|
||||||
|
@Payload("<ws:addPublicIpToNic><ip>{ip}</ip><nicId>{nicid}</nicId></ws:addPublicIpToNic>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String addPublicIpToNic(@PayloadParam("ip") String ip, @PayloadParam("nicid") String nicid);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("publicipblock:removeip")
|
||||||
|
@Payload("<ws:removePublicIpFromNic><ip>{ip}</ip><nicId>{nicid}</nicId></ws:removePublicIpFromNic>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String removePublicIpFromNic(@PayloadParam("ip") String ip, @PayloadParam("nicid") String nicid);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("publicipblock:releaseblock")
|
||||||
|
@Payload("<ws:releasePublicIpBlock><blockId>{blockid}</blockId></ws:releasePublicIpBlock>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String releasePublicIpBlock(@PayloadParam("blockid") String blockid);
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.features;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.binder.loadbalancer.CreateLoadBalancerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.loadbalancer.DeregisterLoadBalancerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.loadbalancer.RegisterLoadBalancerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.loadbalancer.UpdateLoadBalancerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.loadbalancer.LoadBalancerIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.loadbalancer.LoadBalancerListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.loadbalancer.LoadBalancerResponseHandler;
|
||||||
|
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 LoadBalancerApi {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:getall")
|
||||||
|
@Payload("<ws:getAllLoadBalancers/>")
|
||||||
|
@XMLResponseParser(LoadBalancerListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<LoadBalancer> getAllLoadBalancers();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:get")
|
||||||
|
@Payload("<ws:getLoadBalancer><loadBalancerId>{id}</loadBalancerId></ws:getLoadBalancer>")
|
||||||
|
@XMLResponseParser(LoadBalancerResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
LoadBalancer getLoadBalancer(@PayloadParam("id") String identifier);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:create")
|
||||||
|
@MapBinder(CreateLoadBalancerRequestBinder.class)
|
||||||
|
@XMLResponseParser(LoadBalancerIdOnlyResponseHandler.class)
|
||||||
|
String createLoadBalancer(@PayloadParam("loadbalancer") LoadBalancer.Request.CreatePayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:register")
|
||||||
|
@MapBinder(RegisterLoadBalancerRequestBinder.class)
|
||||||
|
@XMLResponseParser(LoadBalancerResponseHandler.class)
|
||||||
|
LoadBalancer registerLoadBalancer(@PayloadParam("loadbalancer") LoadBalancer.Request.RegisterPayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:deregister")
|
||||||
|
@MapBinder(DeregisterLoadBalancerRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String deregisterLoadBalancer(@PayloadParam("loadbalancer") LoadBalancer.Request.DeregisterPayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:delete")
|
||||||
|
@Payload("<ws:deleteLoadBalancer><loadBalancerId>{id}</loadBalancerId></ws:deleteLoadBalancer>")
|
||||||
|
boolean deleteLoadBalancer(@PayloadParam("id") String id);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("loadbalancer:update")
|
||||||
|
@MapBinder(UpdateLoadBalancerRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String updateLoadBalancer(@PayloadParam("loadbalancer") LoadBalancer.Request.UpdatePayload payload);
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* 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 org.jclouds.Fallbacks;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.binder.nic.CreateNicRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.nic.SetInternetAccessBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.nic.UpdateNicRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.nic.NicResponseHandler;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.Payload;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.nic.NicIdOnlyResponseHandler;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface NicApi {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("nics:getall")
|
||||||
|
@Payload("<ws:getAllNic/>")
|
||||||
|
@XMLResponseParser(NicListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<Nic> getAllNics();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("nic:create")
|
||||||
|
@MapBinder(CreateNicRequestBinder.class)
|
||||||
|
@XMLResponseParser(NicIdOnlyResponseHandler.class)
|
||||||
|
String createNic(@PayloadParam("nic") Nic.Request.CreatePayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("nic:get")
|
||||||
|
@Payload("<ws:getNic><nicId>{id}</nicId></ws:getNic>")
|
||||||
|
@XMLResponseParser(NicResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
Nic getNic(@PayloadParam("id") String identifier);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("nic:update")
|
||||||
|
@MapBinder(UpdateNicRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String updateNic(@PayloadParam("nic") Nic.Request.UpdatePayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("nic:setInternetAccess")
|
||||||
|
@MapBinder(SetInternetAccessBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String setInternetAccess(@PayloadParam("nic") Nic.Request.SetInternetAccessPayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("nic:delete")
|
||||||
|
@Payload("<ws:deleteNic><nicId>{id}</nicId></ws:deleteNic>")
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean deleteNic(@PayloadParam("id") String id);
|
||||||
|
}
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.features;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import org.jclouds.Fallbacks;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.binder.server.CreateServerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.server.UpdateServerRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerInfoResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.annotations.Payload;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface ServerApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns information about all virtual server, such as configuration, provisioning status, power status,
|
||||||
|
* etc.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:getall")
|
||||||
|
@Payload("<ws:getAllServers/>")
|
||||||
|
@XMLResponseParser(ServerListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<Server> getAllServers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param identifier Identifier of the virtual server
|
||||||
|
* @return Returns information about a virtual server, such as configuration, provisioning status, power status, etc.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:get")
|
||||||
|
@Payload("<ws:getServer><serverId>{id}</serverId></ws:getServer>")
|
||||||
|
@XMLResponseParser(ServerInfoResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
Server getServer(@PayloadParam("id") String identifier);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an existing virtual server
|
||||||
|
* <ul>
|
||||||
|
* <li>Server may receive new public IP addresses if necessary </li>
|
||||||
|
* <li>Billing will continue</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param id Identifier of the target virtual server
|
||||||
|
* @return Identifier of current request
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:start")
|
||||||
|
@Payload("<ws:startServer><serverId>{id}</serverId></ws:startServer>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String startServer(@PayloadParam("id") String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Stops an existing virtual server forcefully (HARD stop)
|
||||||
|
* <ul>
|
||||||
|
* <li>Server will be forcefully powered off. Any unsaved data may be lost! </li>
|
||||||
|
* <li>Billing for this server will be stopped </li>
|
||||||
|
* <li>When restarting the server a new public IP gets assigned, alternatively, you can reserve IP addresses, see
|
||||||
|
* reservation of public IP blocks</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* A graceful stop of a server is not possible through the ProfitBricks API. We recommend to access and execute the
|
||||||
|
* command on the virtual server directly. Once the server was shutdown you still can use the "stopServer" method
|
||||||
|
* that will stop billing.
|
||||||
|
*
|
||||||
|
* @param id Identifier of the target virtual server
|
||||||
|
* @return Identifier of current request
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:stop")
|
||||||
|
@Payload("<ws:stopServer><serverId>{id}</serverId></ws:stopServer>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String stopServer(@PayloadParam("id") String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets an existing virtual server (POWER CYCLE).
|
||||||
|
* <ul>
|
||||||
|
* <li>Server will be forcefully powered off and restarted immediately. Any unsaved data may be lost!</li>
|
||||||
|
* <li> Billing will continue</li>
|
||||||
|
* </ul>
|
||||||
|
* <b>Graceful REBOOT</b>
|
||||||
|
*
|
||||||
|
* A graceful reboot of a server is not possible through the ProfitBricks API. We recommend to access and execute the
|
||||||
|
* command on the virtual server directly.
|
||||||
|
*
|
||||||
|
* @param id Identifier of the target virtual server
|
||||||
|
* @return Identifier of current request
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:reset")
|
||||||
|
@Payload("<ws:resetServer><serverId>{id}</serverId></ws:resetServer>")
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String resetServer(@PayloadParam("id") String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Virtual Server within an existing data center. Parameters can be specified to set up a boot device and
|
||||||
|
* connect the server to an existing LAN or the Internet.
|
||||||
|
*
|
||||||
|
* @param payload Payload
|
||||||
|
* @return serverId of the created server
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:create")
|
||||||
|
@MapBinder(CreateServerRequestBinder.class)
|
||||||
|
@XMLResponseParser(ServerIdOnlyResponseHandler.class)
|
||||||
|
String createServer(@PayloadParam("server") Server.Request.CreatePayload payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates parameters of an existing virtual server device.
|
||||||
|
*
|
||||||
|
* @param payload Payload
|
||||||
|
* @return Identifier of current request
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:update")
|
||||||
|
@MapBinder(UpdateServerRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String updateServer(@PayloadParam("server") Server.Request.UpdatePayload payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an existing Virtual Server.
|
||||||
|
*
|
||||||
|
* @param id Identifier of the target virtual server
|
||||||
|
* @return Identifier of current request
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Named("server:delete")
|
||||||
|
@Payload("<ws:deleteServer><serverId>{id}</serverId></ws:deleteServer>")
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean deleteServer(@PayloadParam("id") String id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.features;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks;
|
||||||
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
import org.jclouds.profitbricks.binder.snapshot.CreateSnapshotRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.snapshot.RollbackSnapshotRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.binder.snapshot.UpdateSnapshotRequestBinder;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||||
|
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.snapshot.SnapshotResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.snapshot.SnapshotListResponseHandler;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.annotations.Payload;
|
||||||
|
import org.jclouds.rest.annotations.PayloadParam;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||||
|
@Consumes(MediaType.TEXT_XML)
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public interface SnapshotApi {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("snapshot:getall")
|
||||||
|
@Payload("<ws:getAllSnapshots/>")
|
||||||
|
@XMLResponseParser(SnapshotListResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||||
|
List<Snapshot> getAllSnapshots();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("snapshot:get")
|
||||||
|
@Payload("<ws:getSnapshot><snapshotId>{snapshotId}</snapshotId></ws:getSnapshot>")
|
||||||
|
@XMLResponseParser(SnapshotResponseHandler.class)
|
||||||
|
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||||
|
Snapshot getSnapshot(@PayloadParam("snapshotId") String identifier);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("snapshot:create")
|
||||||
|
@MapBinder(CreateSnapshotRequestBinder.class)
|
||||||
|
@XMLResponseParser(SnapshotResponseHandler.class)
|
||||||
|
Snapshot createSnapshot(@PayloadParam("snapshot") Snapshot.Request.CreatePayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("snapshot:update")
|
||||||
|
@MapBinder(UpdateSnapshotRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String updateSnapshot(@PayloadParam("snapshot") Snapshot.Request.UpdatePayload payload);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("snapshot:delete")
|
||||||
|
@Payload("<ws:deleteSnapshot><snapshotId>{id}</snapshotId></ws:deleteSnapshot>")
|
||||||
|
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||||
|
boolean deleteSnapshot(@PayloadParam("id") String id);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Named("snapshot:rollback")
|
||||||
|
@MapBinder(RollbackSnapshotRequestBinder.class)
|
||||||
|
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||||
|
String rollbackSnapshot(@PayloadParam("snapshot") Snapshot.Request.RollbackPayload payload);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.handlers;
|
||||||
|
|
||||||
|
import static org.jclouds.util.Closeables2.closeQuietly;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse ProfitBricks API errors and set the appropriate exception.
|
||||||
|
*
|
||||||
|
* @see org.jclouds.profitbricks.http.ResponseStatusFromPayloadHttpCommandExecutorService
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class ProfitBricksHttpErrorHandler implements HttpErrorHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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("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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import static org.jclouds.util.Closeables2.closeQuietly;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
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;
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
|
import org.jclouds.http.IOExceptionRetryHandler;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
|
import org.jclouds.http.internal.HttpWire;
|
||||||
|
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
|
||||||
|
import org.jclouds.io.ContentMetadataCodec;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
|
import org.jclouds.profitbricks.domain.ServiceFault;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
@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) {
|
||||||
|
super(utils, contentMetadataCodec, retryHandler, ioRetryHandler, errorHandler, wire, verifier, untrustedSSLContextProvider, proxyForURI);
|
||||||
|
this.faultHandler = faultHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpResponse invoke(HttpURLConnection connection) throws IOException, InterruptedException {
|
||||||
|
HttpResponse originalResponse = super.invoke(connection);
|
||||||
|
HttpResponse.Builder<?> responseBuilder = originalResponse.toBuilder();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasServerError(final HttpResponse response) {
|
||||||
|
return response.getStatusCode() >= 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasPayload(final HttpResponse response) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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.filters;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpException;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpRequestFilter;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
|
import org.jclouds.io.ContentMetadata;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters {@link HttpRequest} request and wraps request body into SOAP envelope.
|
||||||
|
*/
|
||||||
|
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>";
|
||||||
|
|
||||||
|
private final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||||
|
checkNotNull(request.getPayload(), "HTTP Request must contain payload message.");
|
||||||
|
return createSoapRequest(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpRequest createSoapRequest(HttpRequest request) {
|
||||||
|
Payload oldPayload = request.getPayload();
|
||||||
|
ContentMetadata oldMetadata = oldPayload.getContentMetadata();
|
||||||
|
|
||||||
|
String body = SOAP_PREFIX.concat(oldPayload.getRawContent().toString()).concat(SOAP_SUFFIX);
|
||||||
|
Payload newPayload = Payloads.newStringPayload(body);
|
||||||
|
HttpUtils.copy(oldMetadata, newPayload.getContentMetadata());
|
||||||
|
newPayload.getContentMetadata().setContentLength(Long.valueOf(body.getBytes().length)); // resize, add prefix/suffix length
|
||||||
|
|
||||||
|
return request.toBuilder().payload(newPayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser;
|
||||||
|
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public abstract class BaseProfitBricksResponseHandler<T> extends ParseSax.HandlerForGeneratedRequestWithResult<T> {
|
||||||
|
|
||||||
|
private final StringBuilder strBuilder;
|
||||||
|
|
||||||
|
public BaseProfitBricksResponseHandler() {
|
||||||
|
this.strBuilder = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
strBuilder.append(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String textToStringValue() {
|
||||||
|
return strBuilder.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Float textToFloatValue() {
|
||||||
|
return Float.valueOf(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Double textToDoubleValue() {
|
||||||
|
return Double.valueOf(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int textToIntValue() {
|
||||||
|
return Integer.parseInt(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean textToBooleanValue() {
|
||||||
|
return Boolean.parseBoolean(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void clearTextBuffer() {
|
||||||
|
strBuilder.setLength(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void endElement(String uri, String localName, String qName) throws SAXException;
|
||||||
|
|
||||||
|
protected abstract void setPropertyOnEndTag(String qName);
|
||||||
|
|
||||||
|
}
|
|
@ -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.http.parser;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class RequestIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||||
|
|
||||||
|
private String requestId;
|
||||||
|
|
||||||
|
RequestIdOnlyResponseHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("requestId".equals(qName))
|
||||||
|
requestId = textToStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getResult() {
|
||||||
|
return requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.ServiceFault;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ServiceFaultResponseHandler extends BaseProfitBricksResponseHandler<ServiceFault> {
|
||||||
|
|
||||||
|
private final ServiceFault.Builder builder;
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
ServiceFaultResponseHandler() {
|
||||||
|
this.builder = ServiceFault.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("faultCode".equals(qName))
|
||||||
|
builder.faultCode(ServiceFault.FaultCode.fromValue(textToStringValue()));
|
||||||
|
else if ("httpCode".equals(qName))
|
||||||
|
builder.httpCode(textToIntValue());
|
||||||
|
else if ("message".equals(qName))
|
||||||
|
builder.message(textToStringValue());
|
||||||
|
else if ("requestId".equals(qName))
|
||||||
|
builder.requestId(textToIntValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("detail".equals(qName))
|
||||||
|
done = true;
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServiceFault getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.datacenter;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
|
||||||
|
public abstract class BaseDataCenterResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected DataCenter.Builder builder;
|
||||||
|
|
||||||
|
BaseDataCenterResponseHandler() {
|
||||||
|
this.builder = DataCenter.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("dataCenterId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("dataCenterVersion".equals(qName))
|
||||||
|
builder.version(textToIntValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* 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.datacenter;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
public class DataCenterInfoResponseHandler extends BaseDataCenterResponseHandler<DataCenter> {
|
||||||
|
|
||||||
|
private final ServerListResponseHandler serverListResponseHandler;
|
||||||
|
private final StorageListResponseHandler storageListResponseHandler;
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
private boolean useServerParser = false;
|
||||||
|
private boolean useStorageParser = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DataCenterInfoResponseHandler(ServerListResponseHandler serverListResponseHandler, StorageListResponseHandler storageListResponseHandler) {
|
||||||
|
this.serverListResponseHandler = serverListResponseHandler;
|
||||||
|
this.storageListResponseHandler = storageListResponseHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
if (useServerParser)
|
||||||
|
serverListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
else if (useStorageParser)
|
||||||
|
storageListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
else
|
||||||
|
super.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
super.setPropertyOnEndTag(qName);
|
||||||
|
if ("dataCenterName".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("location".equals(qName))
|
||||||
|
builder.location(Location.fromId(textToStringValue()));
|
||||||
|
else if ("provisioningState".equals(qName))
|
||||||
|
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
if (useServerParser)
|
||||||
|
serverListResponseHandler.characters(ch, start, length);
|
||||||
|
else if (useStorageParser)
|
||||||
|
storageListResponseHandler.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;
|
||||||
|
|
||||||
|
if (useServerParser)
|
||||||
|
serverListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else if (useStorageParser)
|
||||||
|
storageListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
done = true;
|
||||||
|
builder.servers(serverListResponseHandler.getResult());
|
||||||
|
builder.storages(storageListResponseHandler.getResult());
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("servers".equals(qName))
|
||||||
|
useServerParser = false;
|
||||||
|
else if ("storages".equals(qName))
|
||||||
|
useStorageParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataCenter getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* 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.datacenter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class DataCenterListResponseHandler extends BaseDataCenterResponseHandler<List<DataCenter>> {
|
||||||
|
|
||||||
|
private final List<DataCenter> dataCenters;
|
||||||
|
|
||||||
|
DataCenterListResponseHandler() {
|
||||||
|
this.dataCenters = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DataCenter> getResult() {
|
||||||
|
return dataCenters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
super.setPropertyOnEndTag(qName);
|
||||||
|
if ("dataCenterName".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("location".equals(qName))
|
||||||
|
builder.location(Location.fromValue(textToStringValue()));
|
||||||
|
else if ("provisioningState".equals(qName))
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* 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.firewall;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.rule.FirewallRuleListResponseHandler;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public abstract class BaseFirewallResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected final FirewallRuleListResponseHandler firewallRuleListResponseHandler;
|
||||||
|
|
||||||
|
protected boolean useFirewallRuleParser = false;
|
||||||
|
protected Firewall.Builder builder;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BaseFirewallResponseHandler(FirewallRuleListResponseHandler firewallRuleListResponseHandler) {
|
||||||
|
this.builder = Firewall.builder();
|
||||||
|
this.firewallRuleListResponseHandler = firewallRuleListResponseHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if ("firewallRules".equals(qName))
|
||||||
|
useFirewallRuleParser = true;
|
||||||
|
|
||||||
|
if (useFirewallRuleParser)
|
||||||
|
firewallRuleListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
if (useFirewallRuleParser)
|
||||||
|
firewallRuleListResponseHandler.characters(ch, start, length);
|
||||||
|
else
|
||||||
|
super.characters(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("firewallId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("active".equals(qName))
|
||||||
|
builder.active(textToBooleanValue());
|
||||||
|
else if ("nicId".equals(qName))
|
||||||
|
builder.nicId(textToStringValue());
|
||||||
|
else if ("provisioningState".equals(qName))
|
||||||
|
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.firewall;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.rule.FirewallRuleListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
public class FirewallListResponseHandler extends BaseFirewallResponseHandler<List<Firewall>> {
|
||||||
|
|
||||||
|
private List<Firewall> firewalls;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FirewallListResponseHandler(FirewallRuleListResponseHandler firewallRuleListResponseHandler) {
|
||||||
|
super(firewallRuleListResponseHandler);
|
||||||
|
this.firewalls = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (useFirewallRuleParser)
|
||||||
|
firewallRuleListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName) || "firewall".equals(qName)) {
|
||||||
|
firewalls.add(builder
|
||||||
|
.rules(firewallRuleListResponseHandler.getResult())
|
||||||
|
.build());
|
||||||
|
firewallRuleListResponseHandler.reset();
|
||||||
|
builder = Firewall.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("firewallRules".equals(qName))
|
||||||
|
useFirewallRuleParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.firewalls = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Firewall> getResult() {
|
||||||
|
return firewalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.firewall;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.rule.FirewallRuleListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class FirewallResponseHandler extends BaseFirewallResponseHandler<Firewall> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FirewallResponseHandler(FirewallRuleListResponseHandler firewallRuleListResponseHandler) {
|
||||||
|
super(firewallRuleListResponseHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (useFirewallRuleParser)
|
||||||
|
firewallRuleListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
done = true;
|
||||||
|
builder.rules(firewallRuleListResponseHandler.getResult());
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("firewallRules".equals(qName))
|
||||||
|
useFirewallRuleParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.builder = Firewall.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Firewall 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.firewall.rule;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall;
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall.Protocol;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
|
||||||
|
public abstract class BaseFirewallRuleResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected Firewall.Rule.Builder builder;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BaseFirewallRuleResponseHandler() {
|
||||||
|
this.builder = Firewall.Rule.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("firewallRuleId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("name".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("portRangeEnd".equals(qName))
|
||||||
|
builder.portRangeEnd(textToIntValue());
|
||||||
|
else if ("portRangeStart".equals(qName))
|
||||||
|
builder.portRangeStart(textToIntValue());
|
||||||
|
else if ("protocol".equals(qName))
|
||||||
|
builder.protocol(Protocol.fromValue(textToStringValue()));
|
||||||
|
else if ("sourceIp".equals(qName))
|
||||||
|
builder.sourceIp(textToStringValue());
|
||||||
|
else if ("sourceMac".equals(qName))
|
||||||
|
builder.sourceMac(textToStringValue());
|
||||||
|
else if ("targetIp".equals(qName))
|
||||||
|
builder.targetIp(textToStringValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.firewall.rule;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Firewall.Rule;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
public class FirewallRuleListResponseHandler extends BaseFirewallRuleResponseHandler<List<Rule>> {
|
||||||
|
|
||||||
|
private List<Rule> rules;
|
||||||
|
|
||||||
|
FirewallRuleListResponseHandler() {
|
||||||
|
this.rules = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
|
||||||
|
if ("firewallRules".equals(qName))
|
||||||
|
rules.add(builder.build());
|
||||||
|
clearTextBuffer();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.rules = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Rule> getResult() {
|
||||||
|
return rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.image;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Image;
|
||||||
|
import org.jclouds.profitbricks.domain.Image.Type;
|
||||||
|
import org.jclouds.profitbricks.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.domain.OsType;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
|
||||||
|
public abstract class BaseImageResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected Image.Builder builder;
|
||||||
|
|
||||||
|
BaseImageResponseHandler() {
|
||||||
|
this.builder = Image.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("imageId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("imageName".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("imageSize".equals(qName))
|
||||||
|
builder.size(textToFloatValue());
|
||||||
|
else if ("imageType".equals(qName))
|
||||||
|
builder.type(Type.fromValue(textToStringValue()));
|
||||||
|
else if ("location".equals(qName))
|
||||||
|
builder.location(Location.fromId(textToStringValue()));
|
||||||
|
else if ("osType".equals(qName))
|
||||||
|
builder.osType(OsType.fromValue(textToStringValue()));
|
||||||
|
else if ("public".equals(qName))
|
||||||
|
builder.isPublic(textToBooleanValue());
|
||||||
|
else if ("writeable".equals(qName))
|
||||||
|
builder.isWriteable(textToBooleanValue());
|
||||||
|
else if ("bootable".equals(qName))
|
||||||
|
builder.isBootable(textToBooleanValue());
|
||||||
|
else if ("cpuHotPlug".equals(qName))
|
||||||
|
builder.isCpuHotPlug(textToBooleanValue());
|
||||||
|
else if ("cpuHotUnPlug".equals(qName))
|
||||||
|
builder.isCpuHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("ramHotPlug".equals(qName))
|
||||||
|
builder.isRamHotPlug(textToBooleanValue());
|
||||||
|
else if ("ramHotUnPlug".equals(qName))
|
||||||
|
builder.isRamHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("nicHotPlug".equals(qName))
|
||||||
|
builder.isNicHotPlug(textToBooleanValue());
|
||||||
|
else if ("nicHotUnPlug".equals(qName))
|
||||||
|
builder.isNicHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("discVirtioHotPlug".equals(qName))
|
||||||
|
builder.isDiscVirtioHotPlug(textToBooleanValue());
|
||||||
|
else if ("discVirtioHotUnPlug".equals(qName))
|
||||||
|
builder.isDiscVirtioHotUnPlug(textToBooleanValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.image;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Image;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ImageInfoResponseHandler extends BaseImageResponseHandler<Image> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
ImageInfoResponseHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName))
|
||||||
|
done = true;
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.image;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Image;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ImageListResponseHandler extends BaseImageResponseHandler<List<Image>> {
|
||||||
|
|
||||||
|
private final List<Image> images;
|
||||||
|
|
||||||
|
ImageListResponseHandler() {
|
||||||
|
this.images = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
images.add(builder.build());
|
||||||
|
builder = Image.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Image> getResult() {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.ipblock;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.IpBlock;
|
||||||
|
import org.jclouds.profitbricks.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public abstract class BaseIpBlockResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected final PublicIpListResponseHandler publicIpListResponseHandler;
|
||||||
|
protected List<String> ips;
|
||||||
|
|
||||||
|
protected IpBlock.Builder builder;
|
||||||
|
protected boolean usePublicIpListParser = false;
|
||||||
|
|
||||||
|
BaseIpBlockResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
|
||||||
|
this.builder = IpBlock.builder();
|
||||||
|
this.publicIpListResponseHandler = publicIpListResponseHandler;
|
||||||
|
this.ips = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if ("publicIps".equals(qName))
|
||||||
|
usePublicIpListParser = true;
|
||||||
|
if (usePublicIpListParser)
|
||||||
|
publicIpListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
if (usePublicIpListParser)
|
||||||
|
publicIpListResponseHandler.characters(ch, start, length);
|
||||||
|
else
|
||||||
|
super.characters(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("blockId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("location".equals(qName))
|
||||||
|
builder.location(Location.fromId(textToStringValue()));
|
||||||
|
else if ("ips".equals(qName))
|
||||||
|
ips.add(textToStringValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.ipblock;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.IpBlock;
|
||||||
|
import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
public class IpBlockListResponseHandler extends BaseIpBlockResponseHandler<List<IpBlock>> {
|
||||||
|
|
||||||
|
private final List<IpBlock> ipBlocks;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
IpBlockListResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
|
||||||
|
super(publicIpListResponseHandler);
|
||||||
|
ipBlocks = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (usePublicIpListParser)
|
||||||
|
publicIpListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
ipBlocks.add(builder
|
||||||
|
.publicIps(publicIpListResponseHandler.getResult())
|
||||||
|
.build());
|
||||||
|
publicIpListResponseHandler.reset();
|
||||||
|
builder = IpBlock.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("publicIps".equals(qName))
|
||||||
|
usePublicIpListParser = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IpBlock> getResult() {
|
||||||
|
return ipBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.ipblock;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import org.jclouds.profitbricks.domain.IpBlock;
|
||||||
|
import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class IpBlockResponseHandler extends BaseIpBlockResponseHandler<IpBlock> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
IpBlockResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
|
||||||
|
super(publicIpListResponseHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (usePublicIpListParser)
|
||||||
|
publicIpListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
done = true;
|
||||||
|
builder.publicIps(publicIpListResponseHandler.getResult())
|
||||||
|
.ips(ips);
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("publicIps".equals(qName))
|
||||||
|
usePublicIpListParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.builder = IpBlock.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IpBlock getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* 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.loadbalancer;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer.Algorithm;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public abstract class BaseLoadBalancerResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected final ServerListResponseHandler balancedServerResponseHandler;
|
||||||
|
protected final FirewallListResponseHandler firewallListResponseHandler;
|
||||||
|
|
||||||
|
protected LoadBalancer.Builder builder;
|
||||||
|
protected DataCenter.Builder dataCenterBuilder;
|
||||||
|
|
||||||
|
protected final DateService dateService;
|
||||||
|
|
||||||
|
protected boolean useBalancedServerParser = false;
|
||||||
|
protected boolean useFirewallParser = false;
|
||||||
|
|
||||||
|
protected BaseLoadBalancerResponseHandler(DateService dateService,
|
||||||
|
ServerListResponseHandler balancedServerResponseHandler, FirewallListResponseHandler firewallResponseHandler) {
|
||||||
|
|
||||||
|
checkNotNull(dateService, "DateService cannot be null");
|
||||||
|
checkNotNull(balancedServerResponseHandler, "BalancedServerResponseHandler cannot be null");
|
||||||
|
checkNotNull(firewallResponseHandler, "FirewallListResponseHandler cannot be null");
|
||||||
|
|
||||||
|
this.dateService = dateService;
|
||||||
|
this.builder = LoadBalancer.builder();
|
||||||
|
this.dataCenterBuilder = DataCenter.builder();
|
||||||
|
|
||||||
|
this.balancedServerResponseHandler = balancedServerResponseHandler;
|
||||||
|
this.firewallListResponseHandler = firewallResponseHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if ("balancedServers".equals(qName))
|
||||||
|
useBalancedServerParser = true;
|
||||||
|
if ("firewall".equals(qName))
|
||||||
|
useFirewallParser = true;
|
||||||
|
|
||||||
|
if (useBalancedServerParser)
|
||||||
|
balancedServerResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
else if (useFirewallParser)
|
||||||
|
firewallListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
if (useBalancedServerParser)
|
||||||
|
balancedServerResponseHandler.characters(ch, start, length);
|
||||||
|
else if (useFirewallParser)
|
||||||
|
firewallListResponseHandler.characters(ch, start, length);
|
||||||
|
else
|
||||||
|
super.characters(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Date textToIso8601Date() {
|
||||||
|
return dateService.iso8601DateOrSecondsDateParse(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("loadBalancerId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("loadBalancerName".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("loadBalancerAlgorithm".equals(qName))
|
||||||
|
builder.algorithm(Algorithm.fromValue(textToStringValue()));
|
||||||
|
else if ("dataCenterId".equals(qName))
|
||||||
|
dataCenterBuilder.id(textToStringValue());
|
||||||
|
else if ("dataCenterVersion".equals(qName))
|
||||||
|
dataCenterBuilder.version(textToIntValue());
|
||||||
|
else if ("internetAccess".equals(qName))
|
||||||
|
builder.internetAccess(textToBooleanValue());
|
||||||
|
else if ("ip".equals(qName))
|
||||||
|
builder.ip(textToStringValue());
|
||||||
|
else if ("lanId".equals(qName))
|
||||||
|
builder.lanId(textToIntValue());
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.loadbalancer;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for parsing SOAP response where <i>loadBalancerId</i> is the only <i>usable</i> value.
|
||||||
|
*
|
||||||
|
* Other properties available (which are ignored): requestId, dataCenterId, dataCenterVersion
|
||||||
|
*/
|
||||||
|
public class LoadBalancerIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||||
|
|
||||||
|
private String loadBalancerId;
|
||||||
|
|
||||||
|
LoadBalancerIdOnlyResponseHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("loadBalancerId".equals(qName))
|
||||||
|
loadBalancerId = textToStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getResult() {
|
||||||
|
return loadBalancerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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.loadbalancer;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class LoadBalancerListResponseHandler extends BaseLoadBalancerResponseHandler<List<LoadBalancer>> {
|
||||||
|
|
||||||
|
private final List<LoadBalancer> loadBalancers;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LoadBalancerListResponseHandler(DateService dateService, ServerListResponseHandler balancedServerResponseHandler, FirewallListResponseHandler firewallListResponseHandler) {
|
||||||
|
super(dateService, balancedServerResponseHandler, firewallListResponseHandler);
|
||||||
|
this.loadBalancers = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (useBalancedServerParser)
|
||||||
|
balancedServerResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else if (useFirewallParser)
|
||||||
|
firewallListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
loadBalancers.add(builder
|
||||||
|
.dataCenter(dataCenterBuilder.build())
|
||||||
|
.firewalls(firewallListResponseHandler.getResult())
|
||||||
|
.balancedServers(balancedServerResponseHandler.getResult())
|
||||||
|
.build());
|
||||||
|
|
||||||
|
balancedServerResponseHandler.reset();
|
||||||
|
firewallListResponseHandler.reset();
|
||||||
|
|
||||||
|
builder = LoadBalancer.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
if ("firewall".equals(qName))
|
||||||
|
useFirewallParser = false;
|
||||||
|
else if ("balancedServers".equals(qName))
|
||||||
|
useBalancedServerParser = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.dataCenterBuilder = DataCenter.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<LoadBalancer> getResult() {
|
||||||
|
return loadBalancers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.loadbalancer;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.LoadBalancer;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class LoadBalancerResponseHandler extends BaseLoadBalancerResponseHandler<LoadBalancer> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LoadBalancerResponseHandler(DateService dateService, ServerListResponseHandler serverListResponseHandler,
|
||||||
|
FirewallListResponseHandler firewallListResponseHandler) {
|
||||||
|
super(dateService, serverListResponseHandler, firewallListResponseHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (useBalancedServerParser)
|
||||||
|
balancedServerResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else if (useFirewallParser)
|
||||||
|
firewallListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
done = true;
|
||||||
|
builder.dataCenter(dataCenterBuilder.build())
|
||||||
|
.balancedServers(balancedServerResponseHandler.getResult())
|
||||||
|
.firewalls(firewallListResponseHandler.getResult());
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("balancedServers".equals(qName))
|
||||||
|
useBalancedServerParser = false;
|
||||||
|
else if ("firewall".equals(qName))
|
||||||
|
useFirewallParser = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoadBalancer getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.nic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public abstract class BaseNicResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected final FirewallResponseHandler firewallResponseHandler;
|
||||||
|
|
||||||
|
protected boolean useFirewallParser = false;
|
||||||
|
protected Nic.Builder builder;
|
||||||
|
protected List<String> ips;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BaseNicResponseHandler(FirewallResponseHandler firewallResponseHandler) {
|
||||||
|
this.builder = Nic.builder();
|
||||||
|
this.firewallResponseHandler = firewallResponseHandler;
|
||||||
|
this.ips = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if ("firewall".equals(qName))
|
||||||
|
useFirewallParser = true;
|
||||||
|
if (useFirewallParser)
|
||||||
|
firewallResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
if (useFirewallParser)
|
||||||
|
firewallResponseHandler.characters(ch, start, length);
|
||||||
|
else
|
||||||
|
super.characters(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("dataCenterId".equals(qName))
|
||||||
|
builder.dataCenterId(textToStringValue());
|
||||||
|
else if ("nicName".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("nicId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("lanId".equals(qName))
|
||||||
|
builder.lanId(textToIntValue());
|
||||||
|
else if ("internetAccess".equals(qName))
|
||||||
|
builder.internetAccess(textToBooleanValue());
|
||||||
|
else if ("serverId".equals(qName))
|
||||||
|
builder.serverId(textToStringValue());
|
||||||
|
else if ("ips".equals(qName))
|
||||||
|
ips.add(textToStringValue());
|
||||||
|
else if ("macAddress".equals(qName))
|
||||||
|
builder.macAddress(textToStringValue());
|
||||||
|
else if ("dhcpActive".equals(qName))
|
||||||
|
builder.dhcpActive(textToBooleanValue());
|
||||||
|
else if ("gatewayIp".equals(qName))
|
||||||
|
builder.gatewayIp(textToStringValue());
|
||||||
|
else if ("provisioningState".equals(qName))
|
||||||
|
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.nic;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for parsing SOAP response where <i>nicId</i> is the only <i>usable</i> value.
|
||||||
|
*
|
||||||
|
* Other properties available (which are ignored): requestId, dataCenterId, dataCenterVersion
|
||||||
|
*/
|
||||||
|
public class NicIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||||
|
|
||||||
|
private String nicId;
|
||||||
|
|
||||||
|
NicIdOnlyResponseHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("nicId".equals(qName))
|
||||||
|
nicId = textToStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getResult() {
|
||||||
|
return nicId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* 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.nic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
|
||||||
|
|
||||||
|
public class NicListResponseHandler extends BaseNicResponseHandler<List<Nic>> {
|
||||||
|
|
||||||
|
private List<Nic> nics;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public NicListResponseHandler(FirewallResponseHandler firewallResponseHandler) {
|
||||||
|
super(firewallResponseHandler);
|
||||||
|
this.nics = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (useFirewallParser)
|
||||||
|
firewallResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName) || "nics".equals(qName)) {
|
||||||
|
nics.add(builder
|
||||||
|
.ips(ips)
|
||||||
|
.firewall(firewallResponseHandler.getResult())
|
||||||
|
.build());
|
||||||
|
builder = Nic.builder();
|
||||||
|
ips = new ArrayList<String>();
|
||||||
|
firewallResponseHandler.reset();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("firewall".equals(qName))
|
||||||
|
useFirewallParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.ips = new ArrayList<String>();
|
||||||
|
this.nics = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Nic> getResult() {
|
||||||
|
return nics;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.nic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Nic;
|
||||||
|
import org.jclouds.profitbricks.http.parser.firewall.FirewallResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class NicResponseHandler extends BaseNicResponseHandler<Nic> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public NicResponseHandler(FirewallResponseHandler firewallResponseHandler) {
|
||||||
|
super(firewallResponseHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (useFirewallParser)
|
||||||
|
firewallResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
done = true;
|
||||||
|
builder.ips(ips)
|
||||||
|
.firewall(firewallResponseHandler.getResult());
|
||||||
|
ips = new ArrayList<String>();
|
||||||
|
firewallResponseHandler.reset();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("firewall".equals(qName))
|
||||||
|
useFirewallParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Nic getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.publicip;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.IpBlock;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
|
||||||
|
public abstract class BasePublicIpResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected IpBlock.PublicIp.Builder builder;
|
||||||
|
|
||||||
|
BasePublicIpResponseHandler() {
|
||||||
|
this.builder = IpBlock.PublicIp.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("ip".equals(qName))
|
||||||
|
builder.ip(textToStringValue());
|
||||||
|
else if ("nicId".equals(qName))
|
||||||
|
builder.nicId(textToStringValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.http.parser.publicip;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.List;
|
||||||
|
import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class PublicIpListResponseHandler extends BasePublicIpResponseHandler<List<PublicIp>> {
|
||||||
|
|
||||||
|
private List<PublicIp> publicIps;
|
||||||
|
|
||||||
|
PublicIpListResponseHandler() {
|
||||||
|
this.publicIps = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
|
||||||
|
if ("publicIps".equals(qName)){
|
||||||
|
publicIps.add(builder.build());
|
||||||
|
this.builder = PublicIp.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.publicIps = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PublicIp> getResult() {
|
||||||
|
return publicIps;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.http.parser.server;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.OsType;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public abstract class BaseServerResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected final StorageListResponseHandler storageListResponseHandler;
|
||||||
|
protected final NicListResponseHandler nicListResponseHandler;
|
||||||
|
|
||||||
|
protected DataCenter.Builder dataCenterBuilder;
|
||||||
|
protected Server.Builder builder;
|
||||||
|
|
||||||
|
protected final DateService dateService;
|
||||||
|
|
||||||
|
protected boolean useStorageParser = false;
|
||||||
|
protected boolean useNicParser = false;
|
||||||
|
|
||||||
|
BaseServerResponseHandler(DateService dateService, StorageListResponseHandler storageListResponseHandler,
|
||||||
|
NicListResponseHandler nicListResponseHandler) {
|
||||||
|
checkNotNull(dateService, "DateService cannot be null");
|
||||||
|
checkNotNull(storageListResponseHandler, "StorageListResponseHandler cannot be null");
|
||||||
|
checkNotNull(nicListResponseHandler, "NicListResponseHandler cannot be null");
|
||||||
|
|
||||||
|
this.dateService = dateService;
|
||||||
|
this.storageListResponseHandler = storageListResponseHandler;
|
||||||
|
this.nicListResponseHandler = nicListResponseHandler;
|
||||||
|
this.builder = Server.builder();
|
||||||
|
this.dataCenterBuilder = DataCenter.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if ("connectedStorages".equals(qName))
|
||||||
|
useStorageParser = true;
|
||||||
|
else if ("nics".equals(qName))
|
||||||
|
useNicParser = true;
|
||||||
|
|
||||||
|
if (useStorageParser)
|
||||||
|
storageListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
else if (useNicParser)
|
||||||
|
nicListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||||
|
else
|
||||||
|
super.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
if (useStorageParser)
|
||||||
|
storageListResponseHandler.characters(ch, start, length);
|
||||||
|
else if (useNicParser)
|
||||||
|
nicListResponseHandler.characters(ch, start, length);
|
||||||
|
else
|
||||||
|
super.characters(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Date textToIso8601Date() {
|
||||||
|
return dateService.iso8601DateOrSecondsDateParse(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("dataCenterId".equals(qName))
|
||||||
|
dataCenterBuilder.id(textToStringValue());
|
||||||
|
else if ("dataCenterVersion".equals(qName))
|
||||||
|
dataCenterBuilder.version(textToIntValue());
|
||||||
|
else 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());
|
||||||
|
else if ("activate".equals(qName))
|
||||||
|
builder.loadBalanced(textToBooleanValue());
|
||||||
|
else if ("balancedNicId".equals(qName))
|
||||||
|
builder.balancedNicId(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.server;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for parsing SOAP response where <i>serverId</i> is the only <i>usable</i> value.
|
||||||
|
*
|
||||||
|
* Other properties available (which are ignored): requestId, dataCenterId, dataCenterVersion
|
||||||
|
*/
|
||||||
|
public class ServerIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||||
|
|
||||||
|
private String serverId;
|
||||||
|
|
||||||
|
ServerIdOnlyResponseHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("serverId".equals(qName))
|
||||||
|
serverId = textToStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getResult() {
|
||||||
|
return serverId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.server;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ServerInfoResponseHandler extends BaseServerResponseHandler<Server> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ServerInfoResponseHandler(DateService dateService, StorageListResponseHandler storageListResponseHandler,
|
||||||
|
NicListResponseHandler nicListResponseHandler) {
|
||||||
|
super(dateService, storageListResponseHandler, nicListResponseHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (useStorageParser)
|
||||||
|
storageListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else if (useNicParser)
|
||||||
|
nicListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
done = true;
|
||||||
|
builder
|
||||||
|
.dataCenter(dataCenterBuilder.build())
|
||||||
|
.storages(storageListResponseHandler.getResult())
|
||||||
|
.nics(nicListResponseHandler.getResult());
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("connectedStorages".equals(qName))
|
||||||
|
useStorageParser = false;
|
||||||
|
else if ("nics".equals(qName))
|
||||||
|
useNicParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Server getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.server;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.DataCenter;
|
||||||
|
import org.jclouds.profitbricks.domain.Server;
|
||||||
|
import org.jclouds.profitbricks.http.parser.nic.NicListResponseHandler;
|
||||||
|
import org.jclouds.profitbricks.http.parser.storage.StorageListResponseHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ServerListResponseHandler extends BaseServerResponseHandler<List<Server>> {
|
||||||
|
|
||||||
|
private List<Server> servers;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ServerListResponseHandler(DateService dateService, StorageListResponseHandler storageListResponseHandler,
|
||||||
|
NicListResponseHandler nicListResponseHandler) {
|
||||||
|
super(dateService, storageListResponseHandler, nicListResponseHandler);
|
||||||
|
this.servers = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
|
||||||
|
if (useStorageParser)
|
||||||
|
storageListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else if (useNicParser)
|
||||||
|
nicListResponseHandler.endElement(uri, localName, qName);
|
||||||
|
else {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName) || "servers".equals(qName) || "balancedServers".equals(qName)) {
|
||||||
|
Server.Builder sdb = null;
|
||||||
|
try {
|
||||||
|
sdb = builder
|
||||||
|
.storages(storageListResponseHandler.getResult())
|
||||||
|
.nics(nicListResponseHandler.getResult());
|
||||||
|
servers.add(sdb
|
||||||
|
// For LoadBalancer's case, there's no DataCenter (may throw NPE on #build()).
|
||||||
|
.dataCenter(dataCenterBuilder.build())
|
||||||
|
.build());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
servers.add(sdb.build());
|
||||||
|
}
|
||||||
|
storageListResponseHandler.reset();
|
||||||
|
nicListResponseHandler.reset();
|
||||||
|
|
||||||
|
builder = Server.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("connectedStorages".equals(qName))
|
||||||
|
useStorageParser = false;
|
||||||
|
else if ("nics".equals(qName))
|
||||||
|
useNicParser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
this.servers = Lists.newArrayList();
|
||||||
|
this.dataCenterBuilder = DataCenter.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Server> getResult() {
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.snapshot;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.Location;
|
||||||
|
import org.jclouds.profitbricks.domain.OsType;
|
||||||
|
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||||
|
|
||||||
|
public abstract class BaseSnapshotResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||||
|
|
||||||
|
protected Snapshot.Builder builder;
|
||||||
|
|
||||||
|
protected final DateService dateService;
|
||||||
|
|
||||||
|
BaseSnapshotResponseHandler(DateService dateService) {
|
||||||
|
this.dateService = dateService;
|
||||||
|
this.builder = Snapshot.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Date textToIso8601Date() {
|
||||||
|
return dateService.iso8601DateOrSecondsDateParse(textToStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPropertyOnEndTag(String qName) {
|
||||||
|
if ("snapshotId".equals(qName))
|
||||||
|
builder.id(textToStringValue());
|
||||||
|
else if ("snapshotName".equals(qName))
|
||||||
|
builder.name(textToStringValue());
|
||||||
|
else if ("snapshotSize".equals(qName))
|
||||||
|
builder.size(textToFloatValue());
|
||||||
|
else if ("osType".equals(qName))
|
||||||
|
builder.osType(OsType.fromValue(textToStringValue()));
|
||||||
|
else if ("location".equals(qName))
|
||||||
|
builder.location(Location.fromId(textToStringValue()));
|
||||||
|
else if ("description".equals(qName))
|
||||||
|
builder.description(qName);
|
||||||
|
else if ("bootable".equals(qName))
|
||||||
|
builder.isBootable(textToBooleanValue());
|
||||||
|
else if ("cpuHotPlug".equals(qName))
|
||||||
|
builder.isCpuHotPlug(textToBooleanValue());
|
||||||
|
else if ("cpuHotUnPlug".equals(qName))
|
||||||
|
builder.isCpuHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("ramHotPlug".equals(qName))
|
||||||
|
builder.isRamHotPlug(textToBooleanValue());
|
||||||
|
else if ("ramHotUnPlug".equals(qName))
|
||||||
|
builder.isRamHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("nicHotPlug".equals(qName))
|
||||||
|
builder.isNicHotPlug(textToBooleanValue());
|
||||||
|
else if ("nicHotUnPlug".equals(qName))
|
||||||
|
builder.isNicHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("discVirtioHotPlug".equals(qName))
|
||||||
|
builder.isDiscVirtioHotPlug(textToBooleanValue());
|
||||||
|
else if ("discVirtioHotUnPlug".equals(qName))
|
||||||
|
builder.isDiscVirtioHotUnPlug(textToBooleanValue());
|
||||||
|
else if ("provisioningState".equals(qName))
|
||||||
|
builder.state(ProvisioningState.fromValue(textToStringValue()));
|
||||||
|
else if ("creationTimestamp".equals(qName))
|
||||||
|
builder.creationTime(textToIso8601Date());
|
||||||
|
else if ("modificationTimestamp".equals(qName))
|
||||||
|
builder.lastModificationTime(textToIso8601Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.snapshot;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
|
||||||
|
public class SnapshotListResponseHandler extends BaseSnapshotResponseHandler<List<Snapshot>> {
|
||||||
|
|
||||||
|
private final List<Snapshot> snapshots;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
SnapshotListResponseHandler(DateService dateService) {
|
||||||
|
super(dateService);
|
||||||
|
this.snapshots = Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName)) {
|
||||||
|
snapshots.add(builder.build());
|
||||||
|
builder = Snapshot.builder();
|
||||||
|
}
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Snapshot> getResult() {
|
||||||
|
return snapshots;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.profitbricks.http.parser.snapshot;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.profitbricks.domain.Snapshot;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class SnapshotResponseHandler extends BaseSnapshotResponseHandler<Snapshot> {
|
||||||
|
|
||||||
|
private boolean done = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
SnapshotResponseHandler(DateService dateService) {
|
||||||
|
super(dateService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
setPropertyOnEndTag(qName);
|
||||||
|
if ("return".equals(qName))
|
||||||
|
done = true;
|
||||||
|
clearTextBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Snapshot getResult() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue