You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/03/12 11:39:24 UTC
[06/10] jclouds-labs git commit: White noise: formatting
White noise: formatting
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/2af28926
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/2af28926
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/2af28926
Branch: refs/heads/master
Commit: 2af289269195c89f8aeeb752de65333d05283f99
Parents: c80d40a
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Thu Mar 5 11:46:12 2015 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Thu Mar 12 11:24:43 2015 +0100
----------------------------------------------------------------------
.../jclouds/azurecompute/AzureComputeApi.java | 28 +--
.../AzureComputeProviderMetadata.java | 17 +-
.../AzureManagementApiMetadata.java | 23 +-
.../binders/DeploymentParamsToXML.java | 96 ++++-----
.../binders/NetworkConfigurationToXML.java | 21 +-
.../binders/NetworkSecurityGroupToXML.java | 1 +
.../binders/OSImageParamsToXML.java | 16 +-
.../jclouds/azurecompute/binders/RoleToXML.java | 19 +-
.../jclouds/azurecompute/binders/RuleToXML.java | 17 +-
.../binders/StorageServiceParamsToXML.java | 24 ++-
.../compute/AzureComputeServiceAdapter.java | 120 ++++++-----
.../AzureComputeServiceContextModule.java | 29 +--
.../AzureComputeSecurityGroupExtension.java | 211 ++++++++++---------
.../functions/DeploymentToNodeMetadata.java | 156 +++++++-------
.../compute/functions/LocationToLocation.java | 7 +-
.../compute/functions/OSImageToImage.java | 90 ++++----
.../compute/functions/RoleSizeToHardware.java | 60 +++---
.../functions/internal/OperatingSystems.java | 24 ++-
...ServiceAndVirtualNetworkThenCreateNodes.java | 167 +++++++++------
...eNodeCredentialsButOverrideFromTemplate.java | 20 +-
.../config/AzureComputeHttpApiModule.java | 7 +-
.../config/AzureComputeParserModule.java | 4 +-
.../config/AzureComputeProperties.java | 6 +-
.../azurecompute/domain/Availability.java | 8 +-
.../azurecompute/domain/CloudService.java | 63 +++---
.../domain/DataVirtualHardDisk.java | 54 ++---
.../jclouds/azurecompute/domain/Deployment.java | 128 +++++++----
.../azurecompute/domain/DeploymentParams.java | 120 +++++++----
.../org/jclouds/azurecompute/domain/Disk.java | 85 +++++---
.../org/jclouds/azurecompute/domain/Error.java | 15 +-
.../jclouds/azurecompute/domain/Location.java | 21 +-
.../domain/NetworkConfiguration.java | 52 +++--
.../domain/NetworkSecurityGroup.java | 17 +-
.../jclouds/azurecompute/domain/OSImage.java | 61 ++++--
.../azurecompute/domain/OSImageParams.java | 47 +++--
.../jclouds/azurecompute/domain/Operation.java | 23 +-
.../org/jclouds/azurecompute/domain/Role.java | 125 +++++++----
.../jclouds/azurecompute/domain/RoleSize.java | 79 +++++--
.../org/jclouds/azurecompute/domain/Rule.java | 13 +-
.../azurecompute/domain/StorageService.java | 17 +-
.../domain/StorageServiceParams.java | 41 ++--
.../azurecompute/features/CloudServiceApi.java | 45 ++--
.../azurecompute/features/DeploymentApi.java | 8 +-
.../jclouds/azurecompute/features/DiskApi.java | 3 +-
.../azurecompute/features/LocationApi.java | 7 +-
.../features/NetworkSecurityGroupApi.java | 25 ++-
.../azurecompute/features/OSImageApi.java | 8 +-
.../features/StorageAccountApi.java | 4 +-
.../features/VirtualMachineApi.java | 23 +-
.../features/VirtualNetworkApi.java | 2 +-
.../functions/Base64EncodeLabel.java | 4 +-
.../functions/OSImageParamsName.java | 4 +-
.../functions/ParseRequestIdHeader.java | 10 +-
.../handlers/AzureComputeErrorHandler.java | 22 +-
.../options/AzureComputeTemplateOptions.java | 118 ++++++-----
.../suppliers/KeyStoreSupplier.java | 39 ++--
.../suppliers/SSLContextWithKeysSupplier.java | 15 +-
.../util/NetworkSecurityGroups.java | 16 +-
.../azurecompute/xml/AddressSpaceHandler.java | 13 +-
.../azurecompute/xml/AttachmentHandler.java | 14 +-
.../azurecompute/xml/AvailabilityHandler.java | 11 +-
.../azurecompute/xml/CloudServiceHandler.java | 29 ++-
.../xml/ConfigurationSetHandler.java | 12 +-
.../xml/DataVirtualHardDiskHandler.java | 16 +-
.../azurecompute/xml/DeploymentHandler.java | 36 +++-
.../jclouds/azurecompute/xml/DiskHandler.java | 25 ++-
.../jclouds/azurecompute/xml/ErrorHandler.java | 11 +-
.../azurecompute/xml/InputEndpointHandler.java | 9 +
.../xml/InstanceEndpointHandler.java | 21 +-
.../xml/ListCloudServicesHandler.java | 18 +-
.../xml/ListDataVirtualHardDisksHandler.java | 8 +-
.../azurecompute/xml/ListDisksHandler.java | 18 +-
.../azurecompute/xml/ListLocationsHandler.java | 15 +-
.../xml/ListNetworkSecurityGroupsHandler.java | 14 +-
.../azurecompute/xml/ListOSImagesHandler.java | 6 +-
.../azurecompute/xml/ListRoleSizesHandler.java | 6 +-
.../xml/ListStorageServicesHandler.java | 5 +-
.../xml/ListVirtualNetworkSitesHandler.java | 14 +-
.../azurecompute/xml/LocationHandler.java | 12 +-
.../xml/NetworkConfigurationHandler.java | 10 +-
.../xml/NetworkSecurityGroupHandler.java | 16 +-
.../azurecompute/xml/OSImageHandler.java | 29 ++-
.../xml/OSVirtualHardDiskHandler.java | 18 +-
.../azurecompute/xml/OperationHandler.java | 18 +-
.../ResourceExtensionParameterValueHandler.java | 15 +-
.../xml/ResourceExtensionReferenceHandler.java | 7 +
.../jclouds/azurecompute/xml/RoleHandler.java | 28 ++-
.../azurecompute/xml/RoleInstanceHandler.java | 18 +-
.../azurecompute/xml/RoleSizeHandler.java | 12 +-
.../jclouds/azurecompute/xml/RuleHandler.java | 25 ++-
.../azurecompute/xml/StorageServiceHandler.java | 11 +-
.../xml/StorageServicePropertiesHandler.java | 13 +-
.../jclouds/azurecompute/xml/SubnetHandler.java | 16 +-
.../azurecompute/xml/SubnetNameHandler.java | 1 +
.../azurecompute/xml/VirtualIPHandler.java | 17 +-
.../xml/VirtualNetworkConfigurationHandler.java | 11 +-
.../xml/VirtualNetworkSiteHandler.java | 12 +-
.../compute/functions/OSImageToImageTest.java | 6 +-
98 files changed, 1931 insertions(+), 1150 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java
index 5c35a85..7985726 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java
@@ -34,16 +34,16 @@ import org.jclouds.azurecompute.features.VirtualNetworkApi;
import org.jclouds.rest.annotations.Delegate;
/**
- * The Windows Azure Service Management API is a REST API for managing your services and
- * deployments.
+ * The Windows Azure Service Management API is a REST API for managing your services and deployments.
* <p/>
*
* @see <a href="http://msdn.microsoft.com/en-us/library/ee460799" >doc</a>
*/
public interface AzureComputeApi extends Closeable {
+
/**
- * The Service Management API includes operations for listing the available data center locations
- * for a cloud service in your subscription.
+ * The Service Management API includes operations for listing the available data center locations for a cloud service
+ * in your subscription.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/gg441299">docs</a>
*/
@@ -51,8 +51,7 @@ public interface AzureComputeApi extends Closeable {
LocationApi getLocationApi();
/**
- * The Service Management API includes operations for managing the cloud services beneath your
- * subscription.
+ * The Service Management API includes operations for managing the cloud services beneath your subscription.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/ee460812">docs</a>
*/
@@ -60,8 +59,7 @@ public interface AzureComputeApi extends Closeable {
CloudServiceApi getCloudServiceApi();
/**
- * The Service Management API includes operations for managing the virtual machines in your
- * subscription.
+ * The Service Management API includes operations for managing the virtual machines in your subscription.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/jj157206">docs</a>
*/
@@ -69,19 +67,17 @@ public interface AzureComputeApi extends Closeable {
DeploymentApi getDeploymentApiForService(@PathParam("serviceName") String serviceName);
/**
- * The Service Management API includes operations for managing the virtual machines in your
- * subscription.
+ * The Service Management API includes operations for managing the virtual machines in your subscription.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/jj157206">docs</a>
*/
// TODO: revisit once we have multi-level @Delegate working
@Delegate
VirtualMachineApi getVirtualMachineApiForDeploymentInService(@PathParam("deploymentName") String deploymentName,
- @PathParam("serviceName") String serviceName);
+ @PathParam("serviceName") String serviceName);
/**
- * The Service Management API includes operations for managing the OS images in your
- * subscription.
+ * The Service Management API includes operations for managing the OS images in your subscription.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/jj157175">docs</a>
*/
@@ -89,8 +85,7 @@ public interface AzureComputeApi extends Closeable {
OSImageApi getOSImageApi();
/**
- * The Service Management API includes operations for Tracking Asynchronous Service Management
- * Requests.
+ * The Service Management API includes operations for Tracking Asynchronous Service Management Requests.
*
* @see <a href="http://msdn.microsoft.com/en-us/library/ee460791">docs</a>
*/
@@ -130,8 +125,7 @@ public interface AzureComputeApi extends Closeable {
StorageAccountApi getStorageAccountApi();
/**
- * The Service Management API includes operations for managing the Network Security Groups in your
- * subscription.
+ * The Service Management API includes operations for managing the Network Security Groups in your subscription.
*
*/
@Delegate
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeProviderMetadata.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeProviderMetadata.java b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeProviderMetadata.java
index 876a521..5872fb3 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeProviderMetadata.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeProviderMetadata.java
@@ -20,6 +20,7 @@ import static org.jclouds.azurecompute.config.AzureComputeProperties.OPERATION_P
import static org.jclouds.azurecompute.config.AzureComputeProperties.OPERATION_POLL_MAX_PERIOD;
import static org.jclouds.azurecompute.config.AzureComputeProperties.OPERATION_TIMEOUT;
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
+
import java.net.URI;
import java.util.Properties;
@@ -46,23 +47,25 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata {
}
public static Properties defaultProperties() {
- Properties properties = AzureManagementApiMetadata.defaultProperties();
+ final Properties properties = AzureManagementApiMetadata.defaultProperties();
properties.setProperty(TEMPLATE, "osFamily=UBUNTU,loginUser=jclouds");
- properties.setProperty(OPERATION_TIMEOUT, "" + 60 * 1000);
- properties.setProperty(OPERATION_POLL_INITIAL_PERIOD, "" + 5);
- properties.setProperty(OPERATION_POLL_MAX_PERIOD, "" + 15);
+ properties.setProperty(OPERATION_TIMEOUT, "60000");
+ properties.setProperty(OPERATION_POLL_INITIAL_PERIOD, "5");
+ properties.setProperty(OPERATION_POLL_MAX_PERIOD, "15");
properties.setProperty(AzureComputeProperties.TCP_RULE_FORMAT, "tcp_%s-%s");
properties.setProperty(AzureComputeProperties.TCP_RULE_REGEXP, "tcp_\\d{1,5}-\\d{1,5}");
return properties;
}
- public AzureComputeProviderMetadata(Builder builder) {
+ public AzureComputeProviderMetadata(final Builder builder) {
super(builder);
}
public static class Builder extends BaseProviderMetadata.Builder {
protected Builder() {
+ super();
+
id("azurecompute")
.name("Microsoft Azure Service Management Service")
.apiMetadata(new AzureManagementApiMetadata())
@@ -80,8 +83,8 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata {
}
@Override
- public Builder fromProviderMetadata(ProviderMetadata in) {
- super.fromProviderMetadata(in);
+ public Builder fromProviderMetadata(final ProviderMetadata providerMetadata) {
+ super.fromProviderMetadata(providerMetadata);
return this;
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/AzureManagementApiMetadata.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureManagementApiMetadata.java b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureManagementApiMetadata.java
index 14f8089..6bafad1 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureManagementApiMetadata.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureManagementApiMetadata.java
@@ -17,6 +17,7 @@
package org.jclouds.azurecompute;
import static org.jclouds.reflect.Reflection2.typeToken;
+
import java.net.URI;
import java.util.Properties;
@@ -43,7 +44,7 @@ public class AzureManagementApiMetadata extends BaseHttpApiMetadata<AzureCompute
this(new Builder());
}
- protected AzureManagementApiMetadata(Builder builder) {
+ protected AzureManagementApiMetadata(final Builder builder) {
super(builder);
}
@@ -54,18 +55,20 @@ public class AzureManagementApiMetadata extends BaseHttpApiMetadata<AzureCompute
public static class Builder extends BaseHttpApiMetadata.Builder<AzureComputeApi, Builder> {
protected Builder() {
+ super();
+
id("azurecompute")
.name("Microsoft Azure Service Management Service API")
.version("2014-10-01")
- .identityName("Path to Management Certificate .p12 file, or PEM string")
- .credentialName("Password to Management Certificate")
- .endpointName("Service Management Endpoint ending in your Subscription Id")
- .documentation(URI.create("http://msdn.microsoft.com/en-us/library/ee460799"))
- .defaultProperties(AzureManagementApiMetadata.defaultProperties())
- .view(typeToken(ComputeServiceContext.class))
- .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
- .add(AzureComputeServiceContextModule.class)
- .add(AzureComputeHttpApiModule.class).build());
+ .identityName("Path to Management Certificate .p12 file, or PEM string")
+ .credentialName("Password to Management Certificate")
+ .endpointName("Service Management Endpoint ending in your Subscription Id")
+ .documentation(URI.create("http://msdn.microsoft.com/en-us/library/ee460799"))
+ .defaultProperties(AzureManagementApiMetadata.defaultProperties())
+ .view(typeToken(ComputeServiceContext.class))
+ .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
+ .add(AzureComputeServiceContextModule.class)
+ .add(AzureComputeHttpApiModule.class).build());
}
@Override
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/DeploymentParamsToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/DeploymentParamsToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/DeploymentParamsToXML.java
index f557734..ae89129 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/DeploymentParamsToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/DeploymentParamsToXML.java
@@ -28,49 +28,50 @@ import com.jamesmurty.utils.XMLBuilder;
public final class DeploymentParamsToXML implements Binder {
- @Override@SuppressWarnings("unchecked")
- public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
DeploymentParams params = DeploymentParams.class.cast(input);
try {
XMLBuilder builder = XMLBuilder.create("Deployment", "http://schemas.microsoft.com/windowsazure")
- .e("Name").t(params.name()).up()
- .e("DeploymentSlot").t("Production").up()
- .e("Label").t(params.name()).up()
- .e("RoleList")
- .e("Role")
- .e("RoleName").t(params.name()).up()
- .e("RoleType").t("PersistentVMRole").up()
- .e("ConfigurationSets");
+ .e("Name").t(params.name()).up()
+ .e("DeploymentSlot").t("Production").up()
+ .e("Label").t(params.name()).up()
+ .e("RoleList")
+ .e("Role")
+ .e("RoleName").t(params.name()).up()
+ .e("RoleType").t("PersistentVMRole").up()
+ .e("ConfigurationSets");
if (params.os() == OSImage.Type.WINDOWS) {
XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Windows
configBuilder.e("ConfigurationSetType").t("WindowsProvisioningConfiguration").up()
- .e("ComputerName").t(params.name()).up()
- .e("AdminPassword").t(params.password()).up()
- .e("ResetPasswordOnFirstLogon").t("false").up()
- .e("EnableAutomaticUpdate").t("false").up()
- .e("DomainJoin")
- .e("Credentials")
- .e("Domain").t(params.name()).up()
- .e("Username").t(params.username()).up()
- .e("Password").t(params.password()).up()
- .up() // Credentials
- .e("JoinDomain").t(params.name()).up()
- .up() // Domain Join
- .e("StoredCertificateSettings").up()
- .up(); // Windows ConfigurationSet
+ .e("ComputerName").t(params.name()).up()
+ .e("AdminPassword").t(params.password()).up()
+ .e("ResetPasswordOnFirstLogon").t("false").up()
+ .e("EnableAutomaticUpdate").t("false").up()
+ .e("DomainJoin")
+ .e("Credentials")
+ .e("Domain").t(params.name()).up()
+ .e("Username").t(params.username()).up()
+ .e("Password").t(params.password()).up()
+ .up() // Credentials
+ .e("JoinDomain").t(params.name()).up()
+ .up() // Domain Join
+ .e("StoredCertificateSettings").up()
+ .up(); // Windows ConfigurationSet
} else if (params.os() == OSImage.Type.LINUX) {
XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Linux
configBuilder.e("ConfigurationSetType").t("LinuxProvisioningConfiguration").up()
- .e("HostName").t(params.name()).up()
- .e("UserName").t(params.username()).up()
- .e("UserPassword").t(params.password()).up()
- .e("DisableSshPasswordAuthentication").t("false").up()
- .e("SSH")
+ .e("HostName").t(params.name()).up()
+ .e("UserName").t(params.username()).up()
+ .e("UserPassword").t(params.password()).up()
+ .e("DisableSshPasswordAuthentication").t("false").up()
+ .e("SSH")
.e("PublicKeys").up()
.e("KeyPairs").up()
- .up(); // Linux ConfigurationSet
+ .up(); // Linux ConfigurationSet
} else {
throw new IllegalArgumentException("Unrecognized os type " + params);
}
@@ -82,10 +83,10 @@ public final class DeploymentParamsToXML implements Binder {
for (DeploymentParams.ExternalEndpoint endpoint : params.externalEndpoints()) {
XMLBuilder inputBuilder = inputEndpoints.e("InputEndpoint");
inputBuilder.e("LocalPort").t(Integer.toString(endpoint.localPort())).up()
- .e("Name").t(endpoint.name()).up()
- .e("Port").t(Integer.toString(endpoint.port())).up()
- .e("Protocol").t(endpoint.protocol().toLowerCase()).up()
- .up(); //InputEndpoint
+ .e("Name").t(endpoint.name()).up()
+ .e("Port").t(Integer.toString(endpoint.port())).up()
+ .e("Protocol").t(endpoint.protocol().toLowerCase()).up()
+ .up(); //InputEndpoint
}
inputEndpoints.up();
@@ -98,19 +99,20 @@ public final class DeploymentParamsToXML implements Binder {
}
builder.up() //ConfigurationSets
- // TODO No Disk should be specified for a Role if using a VMImage
- .e("DataVirtualHardDisks").up()
- .e("OSVirtualHardDisk")
- .e("HostCaching").t("ReadWrite").up()
- .e("MediaLink").t(params.mediaLink().toASCIIString()).up()
- // TODO
- /// If you are using a VM image, it must be specified as VMImageName for the role, not as SourceImageNamefor OSVirtualHardDisk.</Message></Error>]
- .e("SourceImageName").t(params.sourceImageName()).up()
- .e("OS").t(params.os() == LINUX ? "Linux" : "Windows").up()
- .up() //OSVirtualHardDisk
- .e("RoleSize").t(params.size().getText()).up()
- .up() //Role
- .up() //RoleList
+ // TODO No Disk should be specified for a Role if using a VMImage
+ .e("DataVirtualHardDisks").up()
+ .e("OSVirtualHardDisk")
+ .e("HostCaching").t("ReadWrite").up()
+ .e("MediaLink").t(params.mediaLink().toASCIIString()).up()
+ // TODO
+ /// If you are using a VM image, it must be specified as VMImageName for the role,
+ // not as SourceImageNamefor OSVirtualHardDisk.</Message></Error>]
+ .e("SourceImageName").t(params.sourceImageName()).up()
+ .e("OS").t(params.os() == LINUX ? "Linux" : "Windows").up()
+ .up() //OSVirtualHardDisk
+ .e("RoleSize").t(params.size().getText()).up()
+ .up() //Role
+ .up() //RoleList
.e("VirtualNetworkName").t(params.virtualNetworkName()).up();
// TODO: Undeprecate this method as forcing users to wrap a String in guava's ByteSource is not great.
return (R) request.toBuilder().payload(builder.asString()).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkConfigurationToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkConfigurationToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkConfigurationToXML.java
index 3021ef4..ce32b27 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkConfigurationToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkConfigurationToXML.java
@@ -34,7 +34,8 @@ public class NetworkConfigurationToXML implements Binder {
NetworkConfiguration networkConfiguration = NetworkConfiguration.class.cast(input);
try {
- XMLBuilder builder = XMLBuilder.create("NetworkConfiguration", "http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration")
+ XMLBuilder builder = XMLBuilder.create(
+ "NetworkConfiguration", "http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration")
.e("VirtualNetworkConfiguration");
if (networkConfiguration.virtualNetworkConfiguration().dns() == null) {
builder.e("Dns");
@@ -43,14 +44,20 @@ public class NetworkConfigurationToXML implements Binder {
}
if (!networkConfiguration.virtualNetworkConfiguration().virtualNetworkSites().isEmpty()) {
XMLBuilder virtualNetworkSitesBuilder = builder.e("VirtualNetworkSites");
- for (VirtualNetworkSite virtualNetworkSite : networkConfiguration.virtualNetworkConfiguration().virtualNetworkSites()) {
- XMLBuilder virtualNetworkSiteBuilder = virtualNetworkSitesBuilder.e("VirtualNetworkSite").a("name",
- virtualNetworkSite.name()).a("Location", virtualNetworkSite.location());
+ for (VirtualNetworkSite virtualNetworkSite
+ : networkConfiguration.virtualNetworkConfiguration().virtualNetworkSites()) {
+
+ XMLBuilder virtualNetworkSiteBuilder = virtualNetworkSitesBuilder.
+ e("VirtualNetworkSite").
+ a("name", virtualNetworkSite.name()).
+ a("Location", virtualNetworkSite.location());
virtualNetworkSiteBuilder.e("AddressSpace")
- .e("AddressPrefix").t(virtualNetworkSite.addressSpace().addressPrefix()).up();
+ .e("AddressPrefix").
+ t(virtualNetworkSite.addressSpace().addressPrefix()).
+ up();
XMLBuilder subnetBuilder = virtualNetworkSiteBuilder.e("Subnets");
- for (Subnet subnet : virtualNetworkSite.subnets()) {
- subnetBuilder.e("Subnet").a("name", subnet.name()).e("AddressPrefix").t(subnet.addressPrefix());
+ for (Subnet subnet : virtualNetworkSite.subnets()) {
+ subnetBuilder.e("Subnet").a("name", subnet.name()).e("AddressPrefix").t(subnet.addressPrefix());
}
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkSecurityGroupToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkSecurityGroupToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkSecurityGroupToXML.java
index 6ca0ecb..3a42823 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkSecurityGroupToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/NetworkSecurityGroupToXML.java
@@ -25,6 +25,7 @@ import org.jclouds.rest.Binder;
import com.jamesmurty.utils.XMLBuilder;
public class NetworkSecurityGroupToXML implements Binder {
+
@Override
@SuppressWarnings("unchecked")
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/OSImageParamsToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/OSImageParamsToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/OSImageParamsToXML.java
index cab54df..32eaa0a 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/OSImageParamsToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/OSImageParamsToXML.java
@@ -26,16 +26,18 @@ import org.jclouds.rest.Binder;
import com.jamesmurty.utils.XMLBuilder;
public final class OSImageParamsToXML implements Binder {
- @Override@SuppressWarnings("unchecked")
- public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
OSImageParams params = OSImageParams.class.cast(input);
try {
String xml = XMLBuilder.create("OSImage", "http://schemas.microsoft.com/windowsazure")
- .e("Label").t(params.label()).up()
- .e("MediaLink").t(params.mediaLink().toASCIIString()).up()
- .e("Name").t(params.name()).up()
- .e("OS").t(params.os() == LINUX ? "Linux" : "Windows").up()
- .up().asString();
+ .e("Label").t(params.label()).up()
+ .e("MediaLink").t(params.mediaLink().toASCIIString()).up()
+ .e("Name").t(params.name()).up()
+ .e("OS").t(params.os() == LINUX ? "Linux" : "Windows").up()
+ .up().asString();
return (R) request.toBuilder().payload(xml).build();
} catch (Exception e) {
throw propagate(e);
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RoleToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RoleToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RoleToXML.java
index d5690e9..25c9b11 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RoleToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RoleToXML.java
@@ -25,6 +25,7 @@ import org.jclouds.rest.Binder;
import com.jamesmurty.utils.XMLBuilder;
public class RoleToXML implements Binder {
+
@Override
@SuppressWarnings("unchecked")
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
@@ -55,20 +56,20 @@ public class RoleToXML implements Binder {
subnetNames.e("SubnetName").t(subnetName.name()).up();
}
if (configurationSet.networkSecurityGroup() != null
- && !configurationSet.networkSecurityGroup().isEmpty()) {
+ && !configurationSet.networkSecurityGroup().isEmpty()) {
configBuilder.e("NetworkSecurityGroup").t(configurationSet.networkSecurityGroup()).up();
}
}
}
builder.e("DataVirtualHardDisks").up()
- .e("OSVirtualHardDisk")
- .e("HostCaching").t(role.osVirtualHardDisk().hostCaching()).up()
- .e("DiskName").t(role.osVirtualHardDisk().diskName()).up()
- .e("MediaLink").t(role.osVirtualHardDisk().mediaLink().toString()).up()
- .e("SourceImageName").t(role.osVirtualHardDisk().sourceImageName()).up()
- .e("OS").t(role.osVirtualHardDisk().os().toString()).up()
- .up() // DataVirtualHardDisks
- .e("RoleSize").t(role.roleSize().getText());
+ .e("OSVirtualHardDisk")
+ .e("HostCaching").t(role.osVirtualHardDisk().hostCaching()).up()
+ .e("DiskName").t(role.osVirtualHardDisk().diskName()).up()
+ .e("MediaLink").t(role.osVirtualHardDisk().mediaLink().toString()).up()
+ .e("SourceImageName").t(role.osVirtualHardDisk().sourceImageName()).up()
+ .e("OS").t(role.osVirtualHardDisk().os().toString()).up()
+ .up() // DataVirtualHardDisks
+ .e("RoleSize").t(role.roleSize().getText());
return (R) request.toBuilder().payload(builder.asString()).build();
} catch (Exception e) {
throw propagate(e);
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RuleToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RuleToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RuleToXML.java
index 3a34b79..6822728 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RuleToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/RuleToXML.java
@@ -25,20 +25,21 @@ import org.jclouds.rest.Binder;
import com.jamesmurty.utils.XMLBuilder;
public final class RuleToXML implements Binder {
+
@Override
@SuppressWarnings("unchecked")
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
Rule rule = Rule.class.cast(input);
try {
String xml = XMLBuilder.create("Rule", "http://schemas.microsoft.com/windowsazure")
- .e("Type").t(rule.type()).up()
- .e("Priority").t(rule.priority()).up()
- .e("Action").t(rule.action()).up()
- .e("SourceAddressPrefix").t(rule.sourceAddressPrefix()).up()
- .e("SourcePortRange").t(rule.sourcePortRange()).up()
- .e("DestinationAddressPrefix").t(rule.destinationAddressPrefix()).up()
- .e("DestinationPortRange").t(rule.destinationPortRange()).up()
- .e("Protocol").t(rule.protocol()).up().asString();
+ .e("Type").t(rule.type()).up()
+ .e("Priority").t(rule.priority()).up()
+ .e("Action").t(rule.action()).up()
+ .e("SourceAddressPrefix").t(rule.sourceAddressPrefix()).up()
+ .e("SourcePortRange").t(rule.sourcePortRange()).up()
+ .e("DestinationAddressPrefix").t(rule.destinationAddressPrefix()).up()
+ .e("DestinationPortRange").t(rule.destinationPortRange()).up()
+ .e("Protocol").t(rule.protocol()).up().asString();
return (R) request.toBuilder().payload(xml).build();
} catch (Exception e) {
throw propagate(e);
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/binders/StorageServiceParamsToXML.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/StorageServiceParamsToXML.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/StorageServiceParamsToXML.java
index 2589a24..480b8d3 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/StorageServiceParamsToXML.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/StorageServiceParamsToXML.java
@@ -27,20 +27,22 @@ import com.jamesmurty.utils.XMLBuilder;
public final class StorageServiceParamsToXML implements Binder {
- @Override@SuppressWarnings("unchecked")
- public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ @Override
+ @SuppressWarnings("unchecked")
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
StorageServiceParams params = StorageServiceParams.class.cast(input);
try {
- XMLBuilder builder = XMLBuilder.create("CreateStorageServiceInput", "http://schemas.microsoft.com/windowsazure")
- .e("ServiceName").t(params.name()).up()
- //.e("Description").up()
- .e("Label").t(BaseEncoding.base64().encode(params.label().getBytes(Charsets.UTF_16))).up()
- .e("Location").t(params.location()).up()
- //.e("GeoReplicationEnabled").up()
- //.e("ExtendedProperties").up()
- //.e("SecondaryReadEnabled").up()
- .e("AccountType").t(params.accountType().name()).up();
+ XMLBuilder builder = XMLBuilder.create(
+ "CreateStorageServiceInput", "http://schemas.microsoft.com/windowsazure")
+ .e("ServiceName").t(params.name()).up()
+ //.e("Description").up()
+ .e("Label").t(BaseEncoding.base64().encode(params.label().getBytes(Charsets.UTF_16))).up()
+ .e("Location").t(params.location()).up()
+ //.e("GeoReplicationEnabled").up()
+ //.e("ExtendedProperties").up()
+ //.e("SecondaryReadEnabled").up()
+ .e("AccountType").t(params.accountType().name()).up();
return (R) request.toBuilder().payload(builder.asString()).build();
} catch (Exception e) {
throw propagate(e);
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/compute/AzureComputeServiceAdapter.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/AzureComputeServiceAdapter.java b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/AzureComputeServiceAdapter.java
index 632e07d..ea44308 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/AzureComputeServiceAdapter.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/AzureComputeServiceAdapter.java
@@ -21,6 +21,7 @@ import static java.lang.String.format;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.jclouds.azurecompute.domain.Deployment.InstanceStatus.READY_ROLE;
import static org.jclouds.util.Predicates2.retry;
+
import java.net.URI;
import java.util.List;
import java.util.Set;
@@ -59,13 +60,14 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
- * defines the connection between the {@link AzureComputeApi} implementation and the
- * jclouds {@link org.jclouds.compute.ComputeService}
+ * defines the connection between the {@link AzureComputeApi} implementation and the jclouds
+ * {@link org.jclouds.compute.ComputeService}
*/
@Singleton
public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deployment, RoleSize, OSImage, Location> {
private static final String DEFAULT_LOGIN_USER = "jclouds";
+
private static final String DEFAULT_LOGIN_PASSWORD = "Azur3Compute!";
@Resource
@@ -73,11 +75,15 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
protected Logger logger = Logger.NULL;
private final AzureComputeApi api;
+
private final Predicate<String> operationSucceededPredicate;
+
private final AzureComputeConstants azureComputeConstants;
@Inject
- AzureComputeServiceAdapter(final AzureComputeApi api, Predicate<String> operationSucceededPredicate, AzureComputeConstants azureComputeConstants) {
+ AzureComputeServiceAdapter(final AzureComputeApi api,
+ final Predicate<String> operationSucceededPredicate, final AzureComputeConstants azureComputeConstants) {
+
this.api = api;
this.operationSucceededPredicate = operationSucceededPredicate;
this.azureComputeConstants = azureComputeConstants;
@@ -85,13 +91,15 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
@Override
public NodeAndInitialCredentials<Deployment> createNodeWithGroupEncodedIntoName(
- final String group, final String name, Template template) {
+ final String group, final String name, final Template template) {
// azure-specific options
- AzureComputeTemplateOptions templateOptions = template.getOptions().as(AzureComputeTemplateOptions.class);
+ final AzureComputeTemplateOptions templateOptions = template.getOptions().as(AzureComputeTemplateOptions.class);
- final String loginUser = templateOptions.getLoginUser() != null ? templateOptions.getLoginUser() : DEFAULT_LOGIN_USER;
- final String loginPassword = templateOptions.getLoginPassword() != null ? templateOptions.getLoginPassword() : DEFAULT_LOGIN_PASSWORD;
+ final String loginUser = templateOptions.getLoginUser() == null
+ ? DEFAULT_LOGIN_USER : templateOptions.getLoginUser();
+ final String loginPassword = templateOptions.getLoginPassword() == null
+ ? DEFAULT_LOGIN_PASSWORD : templateOptions.getLoginPassword();
final String location = template.getLocation().getId();
final int[] inboundPorts = template.getOptions().getInboundPorts();
@@ -102,13 +110,14 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
logger.debug("Creating a cloud service with name '%s', label '%s' in location '%s'", name, name, location);
String createCloudServiceRequestId = api.getCloudServiceApi().createWithLabelInLocation(name, name, location);
if (!operationSucceededPredicate.apply(createCloudServiceRequestId)) {
- final String message = generateIllegalStateExceptionMessage(createCloudServiceRequestId, azureComputeConstants.operationTimeout());
+ final String message = generateIllegalStateExceptionMessage(
+ createCloudServiceRequestId, azureComputeConstants.operationTimeout());
logger.warn(message);
throw new IllegalStateException(message);
}
logger.info("Cloud Service (%s) created with operation id: %s", name, createCloudServiceRequestId);
- final OSImage.Type os = template.getImage().getOperatingSystem().getFamily() == OsFamily.WINDOWS
+ final OSImage.Type os = template.getImage().getOperatingSystem().getFamily() == OsFamily.WINDOWS
? OSImage.Type.WINDOWS : OSImage.Type.LINUX;
Set<ExternalEndpoint> externalEndpoints = Sets.newHashSet();
for (int inboundPort : inboundPorts) {
@@ -130,7 +139,8 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
logger.debug("Creating a deployment with params '%s' ...", params);
String createDeploymentRequestId = api.getDeploymentApiForService(name).create(params);
if (!operationSucceededPredicate.apply(createDeploymentRequestId)) {
- final String message = generateIllegalStateExceptionMessage(createCloudServiceRequestId, azureComputeConstants.operationTimeout());
+ final String message = generateIllegalStateExceptionMessage(
+ createCloudServiceRequestId, azureComputeConstants.operationTimeout());
logger.warn(message);
logger.debug("Deleting cloud service (%s) ...", name);
deleteCloudService(name);
@@ -155,9 +165,9 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
READY_ROLE, azureComputeConstants.operationTimeout());
api.getDeploymentApiForService(group).delete(name);
api.getCloudServiceApi().delete(name);
- throw new IllegalStateException(format("Deployment %s is being destroyed as its instanceStatus didn't reach " +
- "status %s after %ss. Please, try by increasing `jclouds.azure.operation-timeout` and " +
- " try again", name, READY_ROLE, 30 * 60));
+ throw new IllegalStateException(format("Deployment %s is being destroyed as its instanceStatus didn't reach "
+ + "status %s after %ss. Please, try by increasing `jclouds.azure.operation-timeout` and "
+ + " try again", name, READY_ROLE, 30 * 60));
}
Deployment deployment = api.getDeploymentApiForService(name).get(name);
@@ -166,9 +176,10 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
LoginCredentials.builder().user(loginUser).password(loginPassword).build());
}
- public static String generateIllegalStateExceptionMessage(String operationId, long timeout) {
+ public static String generateIllegalStateExceptionMessage(final String operationId, final long timeout) {
final String warnMessage = format("%s has not been completed within %sms.", operationId, timeout);
- return format("%s. Please, try by increasing `%s` and try again", warnMessage, AzureComputeProperties.OPERATION_TIMEOUT);
+ return format("%s. Please, try by increasing `%s` and try again",
+ warnMessage, AzureComputeProperties.OPERATION_TIMEOUT);
}
@Override
@@ -180,38 +191,38 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
public Iterable<OSImage> listImages() {
List<OSImage> osImages = Lists.newArrayList();
for (OSImage osImage : api.getOSImageApi().list()) {
- if (osImage.location() == null) {
- osImages.add(OSImage.create(
- osImage.name(),
- null,
- osImage.affinityGroup(),
- osImage.label(),
- osImage.description(),
- osImage.category(),
- osImage.os(),
- osImage.publisherName(),
- osImage.mediaLink(),
- osImage.logicalSizeInGB(),
- osImage.eula()
- ));
- } else {
- for (String actualLocation : Splitter.on(';').split(osImage.location())) {
- osImages.add(OSImage.create(
- osImage.name() + "/" + actualLocation,
- actualLocation,
- osImage.affinityGroup(),
- osImage.label() + "/" + actualLocation,
- osImage.description(),
- osImage.category(),
- osImage.os(),
- osImage.publisherName(),
- osImage.mediaLink(),
- osImage.logicalSizeInGB(),
- osImage.eula()
- ));
- }
+ if (osImage.location() == null) {
+ osImages.add(OSImage.create(
+ osImage.name(),
+ null,
+ osImage.affinityGroup(),
+ osImage.label(),
+ osImage.description(),
+ osImage.category(),
+ osImage.os(),
+ osImage.publisherName(),
+ osImage.mediaLink(),
+ osImage.logicalSizeInGB(),
+ osImage.eula()
+ ));
+ } else {
+ for (String actualLocation : Splitter.on(';').split(osImage.location())) {
+ osImages.add(OSImage.create(
+ osImage.name() + "/" + actualLocation,
+ actualLocation,
+ osImage.affinityGroup(),
+ osImage.label() + "/" + actualLocation,
+ osImage.description(),
+ osImage.category(),
+ osImage.os(),
+ osImage.publisherName(),
+ osImage.mediaLink(),
+ osImage.logicalSizeInGB(),
+ osImage.eula()
+ ));
}
}
+ }
return osImages;
}
@@ -235,7 +246,7 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
return FluentIterable.from(api.getCloudServiceApi().list())
.transform(new Function<CloudService, Deployment>() {
@Override
- public Deployment apply(CloudService input) {
+ public Deployment apply(final CloudService input) {
return api.getDeploymentApiForService(input.name()).get(id);
}
})
@@ -266,12 +277,12 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
}
@Override
- public void resumeNode(String id) {
+ public void resumeNode(final String id) {
throw new UnsupportedOperationException();
}
@Override
- public void suspendNode(String id) {
+ public void suspendNode(final String id) {
throw new UnsupportedOperationException();
}
@@ -301,22 +312,25 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Deploym
@VisibleForTesting
public static URI createMediaLink(String storageServiceName, String diskName) {
- return URI.create(String.format("https://%s.blob.core.windows.net/vhds/disk-%s.vhd", storageServiceName, diskName));
+ return URI.create(
+ String.format("https://%s.blob.core.windows.net/vhds/disk-%s.vhd", storageServiceName, diskName));
}
- private void deleteCloudService(String name) {
+ private void deleteCloudService(final String name) {
String deleteCloudServiceId = api.getCloudServiceApi().delete(name);
if (!operationSucceededPredicate.apply(deleteCloudServiceId)) {
- final String deleteMessage = generateIllegalStateExceptionMessage(deleteCloudServiceId, azureComputeConstants.operationTimeout());
+ final String deleteMessage = generateIllegalStateExceptionMessage(
+ deleteCloudServiceId, azureComputeConstants.operationTimeout());
logger.warn(deleteMessage);
throw new IllegalStateException(deleteMessage);
}
}
- private void deleteDeployment(String id, String cloudServiceName) {
+ private void deleteDeployment(final String id, final String cloudServiceName) {
String deleteDeploymentId = api.getDeploymentApiForService(cloudServiceName).delete(id);
if (!operationSucceededPredicate.apply(deleteDeploymentId)) {
- final String deleteMessage = generateIllegalStateExceptionMessage(deleteDeploymentId, azureComputeConstants.operationTimeout());
+ final String deleteMessage = generateIllegalStateExceptionMessage(
+ deleteDeploymentId, azureComputeConstants.operationTimeout());
logger.warn(deleteMessage);
throw new IllegalStateException(deleteMessage);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/compute/config/AzureComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/config/AzureComputeServiceContextModule.java b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/config/AzureComputeServiceContextModule.java
index ecdeb23..ca7a290 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/config/AzureComputeServiceContextModule.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/config/AzureComputeServiceContextModule.java
@@ -60,7 +60,7 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
public class AzureComputeServiceContextModule
- extends ComputeServiceAdapterContextModule<Deployment, RoleSize, OSImage, Location> {
+ extends ComputeServiceAdapterContextModule<Deployment, RoleSize, OSImage, Location> {
@Override
protected void configure() {
@@ -80,21 +80,25 @@ public class AzureComputeServiceContextModule
bind(TemplateOptions.class).to(AzureComputeTemplateOptions.class);
- bind(new TypeLiteral<SecurityGroupExtension>() {}).to(AzureComputeSecurityGroupExtension.class);
+ bind(new TypeLiteral<SecurityGroupExtension>() {
+ }).to(AzureComputeSecurityGroupExtension.class);
bind(CreateNodesInGroupThenAddToSet.class).to(GetOrCreateStorageServiceAndVirtualNetworkThenCreateNodes.class);
// to have the compute service adapter override default locations
- install(new LocationsFromComputeServiceAdapterModule<Deployment, RoleSize, OSImage, Location>(){});
+ install(new LocationsFromComputeServiceAdapterModule<Deployment, RoleSize, OSImage, Location>() {
+ });
}
@Override
- protected Optional<SecurityGroupExtension> provideSecurityGroupExtension(Injector i) {
- return Optional.of(i.getInstance(SecurityGroupExtension.class));
+ protected Optional<SecurityGroupExtension> provideSecurityGroupExtension(final Injector injector) {
+ return Optional.of(injector.getInstance(SecurityGroupExtension.class));
}
@Provides
@Singleton
- protected Predicate<String> provideOperationSucceededPredicate(final AzureComputeApi api, AzureComputeConstants azureComputeConstants) {
+ protected Predicate<String> provideOperationSucceededPredicate(
+ final AzureComputeApi api, final AzureComputeConstants azureComputeConstants) {
+
return Predicates2.retry(new OperationSucceededPredicate(api),
azureComputeConstants.operationTimeout(), azureComputeConstants.operationPollInitialPeriod(),
azureComputeConstants.operationPollMaxPeriod());
@@ -104,22 +108,22 @@ public class AzureComputeServiceContextModule
private final AzureComputeApi api;
- public OperationSucceededPredicate(AzureComputeApi api) {
+ public OperationSucceededPredicate(final AzureComputeApi api) {
this.api = checkNotNull(api, "api must not be null");
}
@Override
- public boolean apply(String input) {
- Operation operation = api.getOperationApi().get(input);
+ public boolean apply(final String input) {
+ final Operation operation = api.getOperationApi().get(input);
switch (operation.status()) {
case SUCCEEDED:
return true;
+
case IN_PROGRESS:
- return false;
case FAILED:
- return false;
case UNRECOGNIZED:
return false;
+
default:
throw new IllegalStateException("Operation is in invalid status: " + operation.status().name());
}
@@ -129,6 +133,7 @@ public class AzureComputeServiceContextModule
@Singleton
public static class AzureComputeConstants {
+
@Named(OPERATION_TIMEOUT)
@Inject
private String operationTimeoutProperty;
@@ -164,7 +169,7 @@ public class AzureComputeServiceContextModule
public String tcpRuleFormat() {
return tcpRuleFormatProperty;
}
-
+
public String tcpRuleRegexp() {
return tcpRuleRegexpProperty;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtension.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtension.java b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtension.java
index 1a225d1..278effb 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtension.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtension.java
@@ -58,15 +58,17 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
/**
- * An extension to compute service to allow for the manipulation of {@link org.jclouds.compute.domain.SecurityGroup}s. Implementation
- * is optional by providers.
+ * An extension to compute service to allow for the manipulation of {@link org.jclouds.compute.domain.SecurityGroup}s.
+ * Implementation is optional by providers.
*
* It considers only the custom rules added by the user and ignores the default rules created by Azure
*/
public class AzureComputeSecurityGroupExtension implements SecurityGroupExtension {
protected final AzureComputeApi api;
+
private final Predicate<String> operationSucceededPredicate;
+
private final AzureComputeConstants azureComputeConstants;
@Resource
@@ -74,7 +76,9 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
protected Logger logger = Logger.NULL;
@Inject
- AzureComputeSecurityGroupExtension(final AzureComputeApi api, Predicate<String> operationSucceededPredicate, AzureComputeConstants azureComputeConstants) {
+ AzureComputeSecurityGroupExtension(final AzureComputeApi api,
+ final Predicate<String> operationSucceededPredicate, final AzureComputeConstants azureComputeConstants) {
+
this.api = api;
this.operationSucceededPredicate = operationSucceededPredicate;
this.azureComputeConstants = azureComputeConstants;
@@ -83,8 +87,8 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
@Override
public Set<SecurityGroup> listSecurityGroups() {
return FluentIterable.from(api.getNetworkSecurityGroupApi().list())
- .transform(new NetworkSecurityGroupSecurityGroupFunction())
- .toSet();
+ .transform(new NetworkSecurityGroupSecurityGroupFunction())
+ .toSet();
}
@Override
@@ -99,38 +103,39 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
* @return Set<SecurityGroup>
*/
@Override
- public Set<SecurityGroup> listSecurityGroupsForNode(String name) {
+ public Set<SecurityGroup> listSecurityGroupsForNode(final String name) {
checkNotNull(name, "name");
- Deployment deployment = api.getDeploymentApiForService(name).get(name);
+ final Deployment deployment = api.getDeploymentApiForService(name).get(name);
final String virtualNetworkName = deployment.virtualNetworkName();
- List<String> subnetNames = FluentIterable.from(deployment.roles())
- .transformAndConcat(new Function<Role, Iterable<Role.ConfigurationSet>>() {
- @Override
- public Iterable<Role.ConfigurationSet> apply(Role input) {
- return input.configurationSets();
- }
- })
- .transformAndConcat(new Function<Role.ConfigurationSet, Iterable<Role.ConfigurationSet.SubnetName>>() {
- @Override
- public Iterable<Role.ConfigurationSet.SubnetName> apply(Role.ConfigurationSet input) {
- return input.subnetNames();
- }
- })
- .transform(new Function<Role.ConfigurationSet.SubnetName, String>() {
- @Override
- public String apply(Role.ConfigurationSet.SubnetName input) {
- return input.name();
- }
- })
- .toList();
+ final List<String> subnetNames = FluentIterable.from(deployment.roles())
+ .transformAndConcat(new Function<Role, Iterable<Role.ConfigurationSet>>() {
+ @Override
+ public Iterable<Role.ConfigurationSet> apply(final Role input) {
+ return input.configurationSets();
+ }
+ })
+ .transformAndConcat(new Function<Role.ConfigurationSet, Iterable<Role.ConfigurationSet.SubnetName>>() {
+ @Override
+ public Iterable<Role.ConfigurationSet.SubnetName> apply(final Role.ConfigurationSet input) {
+ return input.subnetNames();
+ }
+ })
+ .transform(new Function<Role.ConfigurationSet.SubnetName, String>() {
+ @Override
+ public String apply(final Role.ConfigurationSet.SubnetName input) {
+ return input.name();
+ }
+ })
+ .toList();
return FluentIterable.from(subnetNames)
.transform(new Function<String, NetworkSecurityGroup>() {
@Override
- public NetworkSecurityGroup apply(String input) {
- return api.getNetworkSecurityGroupApi().getNetworkSecurityGroupAppliedToSubnet(virtualNetworkName, input);
+ public NetworkSecurityGroup apply(final String input) {
+ return api.getNetworkSecurityGroupApi().
+ getNetworkSecurityGroupAppliedToSubnet(virtualNetworkName, input);
}
})
.transform(new NetworkSecurityGroupSecurityGroupFunction())
@@ -138,26 +143,27 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
@Override
- public SecurityGroup getSecurityGroupById(String id) {
+ public SecurityGroup getSecurityGroupById(final String id) {
return transformNetworkSecurityGroupToSecurityGroup(id);
}
@Override
- public SecurityGroup createSecurityGroup(final String name, Location location) {
+ public SecurityGroup createSecurityGroup(final String name, final Location location) {
checkNotNull(name, "name");
checkNotNull(location, "location");
final NetworkSecurityGroup networkSecurityGroup = NetworkSecurityGroup.create(name, name, location.getId(), null);
String createNSGRequestId = api.getNetworkSecurityGroupApi().create(networkSecurityGroup);
if (!operationSucceededPredicate.apply(createNSGRequestId)) {
- final String message = generateIllegalStateExceptionMessage(createNSGRequestId, azureComputeConstants.operationTimeout());
+ final String message = generateIllegalStateExceptionMessage(
+ createNSGRequestId, azureComputeConstants.operationTimeout());
logger.warn(message);
throw new IllegalStateException(message);
}
return transformNetworkSecurityGroupToSecurityGroup(name);
}
- private SecurityGroup transformNetworkSecurityGroupToSecurityGroup(String name) {
+ private SecurityGroup transformNetworkSecurityGroupToSecurityGroup(final String name) {
final NetworkSecurityGroup fullDetails = api.getNetworkSecurityGroupApi().getFullDetails(name);
return fullDetails == null
? null
@@ -165,10 +171,12 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
@Override
- public boolean removeSecurityGroup(String id) {
+ public boolean removeSecurityGroup(final String id) {
final NetworkConfiguration networkConfiguration = api.getVirtualNetworkApi().getNetworkConfiguration();
if (networkConfiguration != null) {
- for (VirtualNetworkSite virtualNetworkSite : networkConfiguration.virtualNetworkConfiguration().virtualNetworkSites()) {
+ for (VirtualNetworkSite virtualNetworkSite
+ : networkConfiguration.virtualNetworkConfiguration().virtualNetworkSites()) {
+
for (NetworkConfiguration.Subnet subnet : virtualNetworkSite.subnets()) {
final String virtualNetworkName = virtualNetworkSite.name();
final String subnetName = subnet.name();
@@ -177,12 +185,14 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
.getNetworkSecurityGroupAppliedToSubnet(virtualNetworkName, subnetName);
if (networkSecurityGroupAppliedToSubnet != null) {
if (!networkSecurityGroupAppliedToSubnet.name().equals(id)) {
- logger.debug("Removing a networkSecurityGroup %s is already applied to subnet '%s' ...", id, subnetName);
+ logger.debug("Removing a networkSecurityGroup %s is already applied to subnet '%s' ...",
+ id, subnetName);
// remove existing nsg from subnet
- String removeFromSubnetRequestId = api.getNetworkSecurityGroupApi().removeFromSubnet
- (virtualNetworkName, subnetName, networkSecurityGroupAppliedToSubnet.name());
+ String removeFromSubnetRequestId = api.getNetworkSecurityGroupApi().removeFromSubnet(
+ virtualNetworkName, subnetName, networkSecurityGroupAppliedToSubnet.name());
if (!operationSucceededPredicate.apply(removeFromSubnetRequestId)) {
- final String message = generateIllegalStateExceptionMessage(removeFromSubnetRequestId, azureComputeConstants.operationTimeout());
+ final String message = generateIllegalStateExceptionMessage(
+ removeFromSubnetRequestId, azureComputeConstants.operationTimeout());
logger.warn(message);
throw new IllegalStateException(message);
}
@@ -197,10 +207,10 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
@Override
- public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
+ public SecurityGroup addIpPermission(final IpPermission ipPermission, final SecurityGroup group) {
checkNotNull(group, "group");
checkNotNull(ipPermission, "ipPermission");
-
+
final String id = checkNotNull(group.getId(), "group.getId()");
final int priority = NetworkSecurityGroups.getFirstAvailablePriority(
@@ -261,16 +271,21 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
}
}
-
+
return transformNetworkSecurityGroupToSecurityGroup(id);
}
@Override
- public SecurityGroup addIpPermission(IpProtocol protocol, int startPort, int endPort,
- Multimap<String, String> tenantIdGroupNamePairs,
- Iterable<String> ipRanges,
- Iterable<String> groupIds, SecurityGroup group) {
- IpPermission.Builder permBuilder = IpPermission.builder();
+ public SecurityGroup addIpPermission(
+ final IpProtocol protocol,
+ final int startPort,
+ final int endPort,
+ final Multimap<String, String> tenantIdGroupNamePairs,
+ final Iterable<String> ipRanges,
+ final Iterable<String> groupIds,
+ final SecurityGroup group) {
+
+ final IpPermission.Builder permBuilder = IpPermission.builder();
permBuilder.ipProtocol(protocol);
permBuilder.fromPort(startPort);
permBuilder.toPort(endPort);
@@ -282,15 +297,15 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
@Override
- public SecurityGroup removeIpPermission(IpPermission ipPermission, SecurityGroup group) {
+ public SecurityGroup removeIpPermission(final IpPermission ipPermission, final SecurityGroup group) {
checkNotNull(group, "group");
checkNotNull(ipPermission, "ipPermission");
-
+
final String id = checkNotNull(group.getId(), "group.getId()");
final String ruleName = NetworkSecurityGroups.createRuleName(
azureComputeConstants.tcpRuleFormat(), ipPermission.getFromPort(), ipPermission.getToPort());
-
+
// remove rule to NSG
removeRuleFromNetworkSecurityGroup(id, ruleName);
@@ -336,16 +351,21 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
}
}
-
+
return transformNetworkSecurityGroupToSecurityGroup(id);
}
@Override
- public SecurityGroup removeIpPermission(IpProtocol protocol, int startPort, int endPort,
- Multimap<String, String> tenantIdGroupNamePairs,
- Iterable<String> ipRanges,
- Iterable<String> groupIds, SecurityGroup group) {
- IpPermission.Builder permBuilder = IpPermission.builder();
+ public SecurityGroup removeIpPermission(
+ final IpProtocol protocol,
+ final int startPort,
+ final int endPort,
+ final Multimap<String, String> tenantIdGroupNamePairs,
+ final Iterable<String> ipRanges,
+ final Iterable<String> groupIds,
+ final SecurityGroup group) {
+
+ final IpPermission.Builder permBuilder = IpPermission.builder();
permBuilder.ipProtocol(protocol);
permBuilder.fromPort(startPort);
permBuilder.toPort(endPort);
@@ -384,8 +404,8 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
private class RuleToIpPermission implements Function<Rule, IpPermission> {
@Override
- public IpPermission apply(Rule rule) {
- IpPermission.Builder builder = IpPermission.builder();
+ public IpPermission apply(final Rule rule) {
+ final IpPermission.Builder builder = IpPermission.builder();
if (rule.name().matches(azureComputeConstants.tcpRuleRegexp())) {
builder.fromPort(extractPort(rule.name(), 0))
.toPort(extractPort(rule.name(), 1));
@@ -400,71 +420,74 @@ public class AzureComputeSecurityGroupExtension implements SecurityGroupExtensio
}
private int extractPort(String ruleName, int position) {
- return Integer.parseInt(Iterables.get(Splitter.on("-").omitEmptyStrings().split(ruleName.substring(4, ruleName.length())),
- position));
+ return Integer.parseInt(Iterables.get(Splitter.on("-").omitEmptyStrings().
+ split(ruleName.substring(4, ruleName.length())), position));
}
}
private class NetworkSecurityGroupSecurityGroupFunction implements Function<NetworkSecurityGroup, SecurityGroup> {
+
@Override
- public SecurityGroup apply(NetworkSecurityGroup networkSecurityGroup) {
- SecurityGroupBuilder securityGroupBuilder = new SecurityGroupBuilder()
+ public SecurityGroup apply(final NetworkSecurityGroup networkSecurityGroup) {
+ final SecurityGroupBuilder securityGroupBuilder = new SecurityGroupBuilder()
.id(networkSecurityGroup.name())
.providerId(networkSecurityGroup.label())
.name(networkSecurityGroup.name());
if (networkSecurityGroup.rules() != null) {
- List<Rule> filteredRules = NetworkSecurityGroups.getCustomRules(networkSecurityGroup);
+ final List<Rule> filteredRules = NetworkSecurityGroups.getCustomRules(networkSecurityGroup);
- Iterable<IpPermission> permissions = Iterables.transform(filteredRules, new RuleToIpPermission());
+ final Iterable<IpPermission> permissions = Iterables.transform(filteredRules, new RuleToIpPermission());
securityGroupBuilder.ipPermissions(permissions);
}
return securityGroupBuilder.build();
}
}
- private void addRuleToNetworkSecurityGroup(String networkSecurityGroupId, String ruleName, int
- priority, IpPermission ipPermission) {
-
- String protocol = ipPermission.getIpProtocol().name();
- String destinationPortRange;
- if (ipPermission.getFromPort() != ipPermission.getToPort()) {
- destinationPortRange = String.format("%s-%s", ipPermission.getFromPort(), ipPermission.getToPort());
- } else {
- destinationPortRange = String.valueOf(ipPermission.getToPort());
- }
- final String destinationAddressPrefix =
- ipPermission.getCidrBlocks().isEmpty() || Iterables.get(ipPermission.getCidrBlocks(), 0).equals("0.0.0.0/0") ?
- "*" : Iterables.get(ipPermission.getCidrBlocks(), 0);
- String setRuleToNSGRequestId = api.getNetworkSecurityGroupApi().setRule(networkSecurityGroupId, ruleName,
- Rule.create(ruleName, // name
- "Inbound", // type
- String.valueOf(priority), // priority
- "Allow", // action
- "INTERNET", // sourceAddressPrefix
- "*", // sourcePortRange
- destinationAddressPrefix, // destinationAddressPrefix
- destinationPortRange, // destinationPortRange
- protocol, // protocol
- "Active", // state
- true // isDefault
- ));
+ private void addRuleToNetworkSecurityGroup(final String networkSecurityGroupId, final String ruleName,
+ final int priority, final IpPermission ipPermission) {
+
+ final String protocol = ipPermission.getIpProtocol().name();
+ final String destinationPortRange = ipPermission.getFromPort() == ipPermission.getToPort()
+ ? String.valueOf(ipPermission.getToPort())
+ : String.format("%s-%s", ipPermission.getFromPort(), ipPermission.getToPort());
+ final String destinationAddressPrefix
+ = ipPermission.getCidrBlocks().isEmpty() || Iterables.get(ipPermission.getCidrBlocks(), 0).equals("0.0.0.0/0")
+ ? "*"
+ : Iterables.get(ipPermission.getCidrBlocks(), 0);
+ final String setRuleToNSGRequestId = api.getNetworkSecurityGroupApi().
+ setRule(networkSecurityGroupId, ruleName, Rule.create(ruleName, // name
+ "Inbound", // type
+ String.valueOf(priority), // priority
+ "Allow", // action
+ "INTERNET", // sourceAddressPrefix
+ "*", // sourcePortRange
+ destinationAddressPrefix, // destinationAddressPrefix
+ destinationPortRange, // destinationPortRange
+ protocol, // protocol
+ "Active", // state
+ true // isDefault
+ ));
if (!operationSucceededPredicate.apply(setRuleToNSGRequestId)) {
- final String message = generateIllegalStateExceptionMessage(setRuleToNSGRequestId, azureComputeConstants.operationTimeout());
+ final String message = generateIllegalStateExceptionMessage(
+ setRuleToNSGRequestId, azureComputeConstants.operationTimeout());
logger.warn(message);
throw new IllegalStateException(message);
}
}
- private void removeRuleFromNetworkSecurityGroup(String id, String ruleName) {
+ private void removeRuleFromNetworkSecurityGroup(final String id, final String ruleName) {
String setRuleToNSGRequestId = api.getNetworkSecurityGroupApi().deleteRule(id, ruleName);
if (!operationSucceededPredicate.apply(setRuleToNSGRequestId)) {
- final String message = generateIllegalStateExceptionMessage(setRuleToNSGRequestId, azureComputeConstants.operationTimeout());
+ final String message = generateIllegalStateExceptionMessage(
+ setRuleToNSGRequestId, azureComputeConstants.operationTimeout());
logger.warn(message);
throw new IllegalStateException(message);
}
}
- private Role.ConfigurationSet.InputEndpoint createInputEndpoint(String ruleName, String protocol, String address, int port) {
+ private Role.ConfigurationSet.InputEndpoint createInputEndpoint(
+ final String ruleName, final String protocol, final String address, final int port) {
+
return Role.ConfigurationSet.InputEndpoint.create(
ruleName,
protocol,
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
index 0d099e8..297bba6 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/DeploymentToNodeMetadata.java
@@ -38,86 +38,90 @@ import com.google.common.collect.Sets;
public class DeploymentToNodeMetadata implements Function<Deployment, NodeMetadata> {
- private final Supplier<Set<? extends Location>> locations;
- private final GroupNamingConvention nodeNamingConvention;
- private final OSImageToImage osImageToImage;
- private final RoleSizeToHardware roleSizeToHardware;
- private final Map<String, Credentials> credentialStore;
-
- public static final Map<Deployment.Status, NodeMetadata.Status> serverStateToNodeStatus = ImmutableMap
- .<Deployment.Status, NodeMetadata.Status> builder()
- .put(Deployment.Status.DELETING, NodeMetadata.Status.PENDING)
- .put(Deployment.Status.SUSPENDED_TRANSITIONING, NodeMetadata.Status.PENDING)
- .put(Deployment.Status.RUNNING_TRANSITIONING, NodeMetadata.Status.PENDING)
- .put(Deployment.Status.DEPLOYING, NodeMetadata.Status.PENDING)
- .put(Deployment.Status.STARTING, NodeMetadata.Status.PENDING)
- .put(Deployment.Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)
- .put(Deployment.Status.RUNNING, NodeMetadata.Status.RUNNING)
- .put(Deployment.Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build();
-
- @Inject
- DeploymentToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
- GroupNamingConvention.Factory namingConvention, OSImageToImage osImageToImage,
- RoleSizeToHardware roleSizeToHardware, Map<String, Credentials> credentialStore) {
- this.nodeNamingConvention = namingConvention.createWithoutPrefix();
- this.locations = locations;
- this.osImageToImage = osImageToImage;
- this.roleSizeToHardware = roleSizeToHardware;
- this.credentialStore = credentialStore;
- }
-
- @Override
- public NodeMetadata apply(Deployment from) {
- NodeMetadataBuilder builder = new NodeMetadataBuilder();
- builder.id(from.name());
+ private static final Map<Deployment.Status, NodeMetadata.Status> serverStateToNodeStatus
+ = ImmutableMap.<Deployment.Status, NodeMetadata.Status>builder()
+ .put(Deployment.Status.DELETING, NodeMetadata.Status.PENDING)
+ .put(Deployment.Status.SUSPENDED_TRANSITIONING, NodeMetadata.Status.PENDING)
+ .put(Deployment.Status.RUNNING_TRANSITIONING, NodeMetadata.Status.PENDING)
+ .put(Deployment.Status.DEPLOYING, NodeMetadata.Status.PENDING)
+ .put(Deployment.Status.STARTING, NodeMetadata.Status.PENDING)
+ .put(Deployment.Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)
+ .put(Deployment.Status.RUNNING, NodeMetadata.Status.RUNNING)
+ .put(Deployment.Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build();
+
+ private final Supplier<Set<? extends Location>> locations;
+
+ private final GroupNamingConvention nodeNamingConvention;
+
+ private final OSImageToImage osImageToImage;
+
+ private final RoleSizeToHardware roleSizeToHardware;
+
+ private final Map<String, Credentials> credentialStore;
+
+ @Inject
+ DeploymentToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
+ GroupNamingConvention.Factory namingConvention, OSImageToImage osImageToImage,
+ RoleSizeToHardware roleSizeToHardware, Map<String, Credentials> credentialStore) {
+
+ this.nodeNamingConvention = namingConvention.createWithoutPrefix();
+ this.locations = locations;
+ this.osImageToImage = osImageToImage;
+ this.roleSizeToHardware = roleSizeToHardware;
+ this.credentialStore = credentialStore;
+ }
+
+ @Override
+ public NodeMetadata apply(final Deployment from) {
+ final NodeMetadataBuilder builder = new NodeMetadataBuilder();
+ builder.id(from.name());
builder.providerId(from.name());
- builder.name(from.name());
- builder.hostname(getHostname(from));
- /* TODO
- if (from.getDatacenter() != null) {
- builder.location(from(locations.get()).firstMatch(
- LocationPredicates.idEquals(from.getDatacenter().getId() + "")).orNull());
- }
- builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname()));
- builder.hardware(roleSizeToHardware.apply(from.instanceSize()));
- Image image = osImageToImage.apply(from);
- if (image != null) {
- builder.imageId(image.getId());
- builder.operatingSystem(image.getOperatingSystem());
- }
- */
- if (from.status() != null) {
- builder.status(serverStateToNodeStatus.get(from.status()));
- }
- Set<String> publicIpAddresses = Sets.newLinkedHashSet();
- if (from.virtualIPs() != null) {
- for (Deployment.VirtualIP virtualIP : from.virtualIPs()) {
- publicIpAddresses.add(virtualIP.address());
- }
- builder.publicAddresses(publicIpAddresses);
- }
- Set<String> privateIpAddresses = Sets.newLinkedHashSet();
- if (from.roleInstanceList() != null) {
- for (RoleInstance roleInstance : from.roleInstanceList()) {
- privateIpAddresses.add(roleInstance.ipAddress());
- }
- builder.privateAddresses(privateIpAddresses);
- }
- return builder.build();
- }
-
- private String getHostname(Deployment from) {
- final Optional<RoleInstance> roleInstanceOptional = tryFindFirstRoleInstanceInDeployment(from);
- if (!roleInstanceOptional.isPresent()) {
- return from.name();
- } else {
- return roleInstanceOptional.get().hostname();
+ builder.name(from.name());
+ builder.hostname(getHostname(from));
+ /* TODO
+ if (from.getDatacenter() != null) {
+ builder.location(from(locations.get()).firstMatch(
+ LocationPredicates.idEquals(from.getDatacenter().getId() + "")).orNull());
+ }
+ builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname()));
+ builder.hardware(roleSizeToHardware.apply(from.instanceSize()));
+ Image image = osImageToImage.apply(from);
+ if (image != null) {
+ builder.imageId(image.getId());
+ builder.operatingSystem(image.getOperatingSystem());
+ }
+ */
+ if (from.status() != null) {
+ builder.status(serverStateToNodeStatus.get(from.status()));
+ }
+ final Set<String> publicIpAddresses = Sets.newLinkedHashSet();
+ if (from.virtualIPs() != null) {
+ for (Deployment.VirtualIP virtualIP : from.virtualIPs()) {
+ publicIpAddresses.add(virtualIP.address());
+ }
+ builder.publicAddresses(publicIpAddresses);
+ }
+ final Set<String> privateIpAddresses = Sets.newLinkedHashSet();
+ if (from.roleInstanceList() != null) {
+ for (RoleInstance roleInstance : from.roleInstanceList()) {
+ privateIpAddresses.add(roleInstance.ipAddress());
+ }
+ builder.privateAddresses(privateIpAddresses);
}
+ return builder.build();
+ }
+
+ private String getHostname(final Deployment from) {
+ final Optional<RoleInstance> roleInstanceOptional = tryFindFirstRoleInstanceInDeployment(from);
+ return roleInstanceOptional.isPresent()
+ ? roleInstanceOptional.get().hostname()
+ : from.name();
}
- private Optional<RoleInstance> tryFindFirstRoleInstanceInDeployment(Deployment deployment) {
- if (deployment.roleInstanceList() == null || deployment.roleInstanceList().isEmpty()) return Optional.absent();
- return Optional.of(deployment.roleInstanceList().get(0));
+ private Optional<RoleInstance> tryFindFirstRoleInstanceInDeployment(final Deployment deployment) {
+ return (deployment.roleInstanceList() == null || deployment.roleInstanceList().isEmpty())
+ ? Optional.<RoleInstance>absent()
+ : Optional.of(deployment.roleInstanceList().get(0));
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2af28926/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/LocationToLocation.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/LocationToLocation.java b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/LocationToLocation.java
index 228d875..64a7be3 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/LocationToLocation.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/compute/functions/LocationToLocation.java
@@ -34,6 +34,7 @@ import com.google.common.collect.ImmutableSet;
*/
@Singleton
public class LocationToLocation implements Function<Location, org.jclouds.domain.Location> {
+
private final JustProvider justProvider;
// allow us to lazy discover the provider of a resource
@@ -43,13 +44,13 @@ public class LocationToLocation implements Function<Location, org.jclouds.domain
}
@Override
- public org.jclouds.domain.Location apply(Location location) {
- LocationBuilder builder = new LocationBuilder();
+ public org.jclouds.domain.Location apply(final Location location) {
+ final LocationBuilder builder = new LocationBuilder();
builder.id(location.name());
builder.description(location.displayName());
builder.scope(LocationScope.REGION);
builder.parent(getOnlyElement(justProvider.get()));
- builder.iso3166Codes(ImmutableSet.<String> of("name", location.name()));
+ builder.iso3166Codes(ImmutableSet.<String>of("name", location.name()));
return builder.build();
}