http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionParameterValueHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionParameterValueHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionParameterValueHandler.java deleted file mode 100644 index a858195..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionParameterValueHandler.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Role.ResourceExtensionReference.ResourceExtensionParameterValue; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public final class ResourceExtensionParameterValueHandler extends ParseSax.HandlerForGeneratedRequestWithResult<ResourceExtensionParameterValue> { - - private String key; - - private String value; - - private String type; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - } - - @Override - public ResourceExtensionParameterValue getResult() { - ResourceExtensionParameterValue result = ResourceExtensionParameterValue.create(key, value, type); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - key = value = type = null; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Key")) { - key = currentOrNull(currentText); - } else if (qName.equals("Value")) { - value = currentOrNull(currentText); - } else if (qName.equals("Type")) { - type = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } - -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionReferenceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionReferenceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionReferenceHandler.java deleted file mode 100644 index 9a0a4ef..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResourceExtensionReferenceHandler.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; -import java.util.List; - -import org.jclouds.azurecompute.domain.Role.ResourceExtensionReference; -import org.jclouds.azurecompute.domain.Role.ResourceExtensionReference.ResourceExtensionParameterValue; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; -import com.google.inject.Inject; - -public class ResourceExtensionReferenceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<ResourceExtensionReference> { - - private String referenceName; - - private String publisher; - - private String name; - - private String version; - - private List<ResourceExtensionParameterValue> resourceExtensionParameterValues = Lists.newArrayList(); - - private String state; - - private final ResourceExtensionParameterValueHandler resourceExtensionParameterValueHandler; - - private boolean inResourceExtensionParameterValue = false; - - private final StringBuilder currentText = new StringBuilder(); - - @Inject - ResourceExtensionReferenceHandler(ResourceExtensionParameterValueHandler resourceExtensionParameterValueHandler) { - this.resourceExtensionParameterValueHandler = resourceExtensionParameterValueHandler; - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("ResourceExtensionParameterValue")) { - inResourceExtensionParameterValue = true; - } - if (inResourceExtensionParameterValue) { - resourceExtensionParameterValueHandler.startElement(uri, localName, qName, attributes); - } - } - - @Override - public ResourceExtensionReference getResult() { - ResourceExtensionReference result = ResourceExtensionReference.create(referenceName, publisher, name, version, - resourceExtensionParameterValues, state); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - referenceName = publisher = version = name = state = null; - resourceExtensionParameterValues = Lists.newArrayList(); - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("ResourceExtensionParameterValue")) { - inResourceExtensionParameterValue = false; - resourceExtensionParameterValues.add(resourceExtensionParameterValueHandler.getResult()); - } else if (inResourceExtensionParameterValue) { - resourceExtensionParameterValueHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("ReferenceName")) { - referenceName = currentOrNull(currentText); - } else if (qName.equals("Publisher")) { - publisher = currentOrNull(currentText); - } else if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("Version")) { - version = currentOrNull(currentText); - } else if (qName.equals("State")) { - state = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inResourceExtensionParameterValue) { - resourceExtensionParameterValueHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResultHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResultHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResultHandler.java deleted file mode 100644 index 4b78499..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ResultHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.azurecompute.xml; - -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -/** - * @see for example <a href="https://msdn.microsoft.com/en-us/library/azure/dn510368.aspx">Check DNS Prefix - * Availability</a> - */ -public final class ResultHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Boolean> { - - private boolean result = false; - private final StringBuilder currentText = new StringBuilder(); - - @Override - public Boolean getResult() { - final boolean res = result; - resetState(); // handler is called in a loop. - return res; - } - - private void resetState() { - result = false; - } - - @Override - public void startElement( - final String url, - final String name, - final String qName, - final Attributes attributes) { - } - - @Override - public void endElement(final String ignoredURI, final String ignoredName, final String qName) { - if (qName.equals("Result")) { - final String value = currentText.toString().trim(); - result = value.isEmpty() ? false : Boolean.parseBoolean(value); - } - currentText.setLength(0); - - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleHandler.java deleted file mode 100644 index 3dd1481..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleHandler.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; -import java.util.List; - -import org.jclouds.azurecompute.domain.DataVirtualHardDisk; -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet; -import org.jclouds.azurecompute.domain.Role.ResourceExtensionReference; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; -import com.google.inject.Inject; - -public class RoleHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Role> { - - private String roleName; - - private String roleType; - - private String vmImage; - - private String mediaLocation; - - private List<ConfigurationSet> configurationSets = Lists.newArrayList(); - - private List<ResourceExtensionReference> resourceExtensionReferences = Lists.newArrayList(); - - private String availabilitySetName; - - private List<DataVirtualHardDisk> dataVirtualHardDisks = Lists.newArrayList(); - - private Role.OSVirtualHardDisk osVirtualHardDisk; - - private RoleSize.Type roleSize; - - private Boolean provisionGuestAgent; - - private String defaultWinRmCertificateThumbprint; - - private boolean inConfigurationSets; - - private boolean inOSVirtualHardDisk; - - private boolean inDataVirtualHardDisks; - - private boolean inResourceExtensionReference; - - private final ConfigurationSetHandler configurationSetHandler; - - private final OSVirtualHardDiskHandler osVirtualDiskHandler; - - private final DataVirtualHardDiskHandler dataVirtualHardDiskHandler; - - private final ResourceExtensionReferenceHandler resourceExtensionReferenceHandler; - - @Inject - RoleHandler(ConfigurationSetHandler configurationSetHandler, OSVirtualHardDiskHandler osVirtualDiskHandler, - DataVirtualHardDiskHandler dataVirtualHardDiskHandler, ResourceExtensionReferenceHandler resourceExtensionReferenceHandler) { - this.configurationSetHandler = configurationSetHandler; - this.osVirtualDiskHandler = osVirtualDiskHandler; - this.dataVirtualHardDiskHandler = dataVirtualHardDiskHandler; - this.resourceExtensionReferenceHandler = resourceExtensionReferenceHandler; - } - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("ConfigurationSets")) { - inConfigurationSets = true; - } - if (inConfigurationSets) { - configurationSetHandler.startElement(uri, localName, qName, attributes); - } - if (qName.equals("OSVirtualHardDisk")) { - inOSVirtualHardDisk = true; - } - if (qName.equals("DataVirtualHardDisks")) { - inDataVirtualHardDisks = true; - } - if (inDataVirtualHardDisks) { - dataVirtualHardDiskHandler.startElement(uri, localName, qName, attributes); - } - if (qName.equals("ResourceExtensionReference")) { - inResourceExtensionReference = true; - } - if (inResourceExtensionReference) { - resourceExtensionReferenceHandler.startElement(uri, localName, qName, attributes); - } - - } - - private void resetState() { - roleName = roleType = vmImage = mediaLocation = availabilitySetName = defaultWinRmCertificateThumbprint = null; - configurationSets = null; - osVirtualHardDisk = null; - configurationSets = Lists.newArrayList(); - resourceExtensionReferences = Lists.newArrayList(); - dataVirtualHardDisks = Lists.newArrayList(); - roleSize = null; - provisionGuestAgent = null; - } - - @Override - public Role getResult() { - Role result = Role.create(roleName, roleType, vmImage, mediaLocation, configurationSets, - resourceExtensionReferences, availabilitySetName, dataVirtualHardDisks, osVirtualHardDisk, roleSize, - provisionGuestAgent, defaultWinRmCertificateThumbprint); - resetState(); // handler is called in a loop. - return result; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("DataVirtualHardDisks")) { - inDataVirtualHardDisks = false; - } else if (qName.equals("ConfigurationSet")) { - inConfigurationSets = false; - configurationSets.add(configurationSetHandler.getResult()); - } else if (inConfigurationSets) { - configurationSetHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("DataVirtualHardDisks")) { - inDataVirtualHardDisks = false; - dataVirtualHardDisks.add(dataVirtualHardDiskHandler.getResult()); - } else if (inDataVirtualHardDisks) { - dataVirtualHardDiskHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("RoleName")) { - roleName = currentOrNull(currentText); - } else if (qName.equals("VMImage")) { - vmImage = currentOrNull(currentText); - } else if (qName.equals("MediaLocation")) { - mediaLocation = currentOrNull(currentText); - } else if (qName.equals("AvailabilitySetName")) { - availabilitySetName = currentOrNull(currentText); - } else if (qName.equals("DefaultWinRmCertificateThumbprint")) { - defaultWinRmCertificateThumbprint = currentOrNull(currentText); - } else if (qName.equals("RoleType")) { - roleType = currentOrNull(currentText); - } else if (qName.equals("OSVirtualHardDisk")) { - inOSVirtualHardDisk = false; - osVirtualHardDisk = osVirtualDiskHandler.getResult(); - } else if (inOSVirtualHardDisk) { - osVirtualDiskHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("RoleSize")) { - roleSize = RoleSize.Type.fromString(currentOrNull(currentText).toUpperCase()); - } else if (qName.equals("ProvisionGuestAgent")) { - String provisionGuestAgentString = currentOrNull(currentText); - if (provisionGuestAgentString != null) { - provisionGuestAgent = Boolean.valueOf(provisionGuestAgentString); - } - } else if (qName.equals("ResourceExtensionReferences")) { - inResourceExtensionReference = false; - } else if (qName.equals("ResourceExtensionReference")) { - resourceExtensionReferences.add(resourceExtensionReferenceHandler.getResult()); - } else if (inResourceExtensionReference) { - resourceExtensionReferenceHandler.endElement(ignoredUri, ignoredName, qName); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inConfigurationSets) { - configurationSetHandler.characters(ch, start, length); - } else if (inOSVirtualHardDisk) { - osVirtualDiskHandler.characters(ch, start, length); - } else if (inResourceExtensionReference) { - resourceExtensionReferenceHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleInstanceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleInstanceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleInstanceHandler.java deleted file mode 100644 index 524b644..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleInstanceHandler.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.util.List; - -import org.jclouds.azurecompute.domain.Deployment.InstanceEndpoint; -import org.jclouds.azurecompute.domain.Deployment.InstanceStatus; -import org.jclouds.azurecompute.domain.Deployment.PowerState; -import org.jclouds.azurecompute.domain.Deployment.RoleInstance; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; - -public class RoleInstanceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<RoleInstance> { - - private String roleName; - - private String instanceName; - - private InstanceStatus instanceStatus; - - private PowerState powerState; - - private int instanceUpgradeDomain; - - private int instanceFaultDomain; - - private RoleSize.Type instanceSize; - - private String ipAddress; - - private String hostname; - - private boolean inInstanceEndpoints; - - private final InstanceEndpointHandler instanceEndpointHandler = new InstanceEndpointHandler(); - - private List<InstanceEndpoint> instanceEndpoints = Lists.newArrayList(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("InstanceEndpoints")) { - inInstanceEndpoints = true; - } - if (inInstanceEndpoints) { - instanceEndpointHandler.startElement(uri, localName, qName, attributes); - } - } - - private void resetState() { - roleName = instanceName = ipAddress = hostname = null; - instanceStatus = null; - powerState = null; - instanceUpgradeDomain = instanceFaultDomain = -1; - instanceSize = null; - instanceEndpoints = Lists.newArrayList(); - } - - private StringBuilder currentText = new StringBuilder(); - - @Override - public RoleInstance getResult() { - RoleInstance result = RoleInstance.create(roleName, instanceName, instanceStatus, powerState, - instanceUpgradeDomain, instanceFaultDomain, instanceSize, ipAddress, hostname, instanceEndpoints); - resetState(); // handler is called in a loop. - return result; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("InstanceEndpoints")) { - inInstanceEndpoints = false; - } else if (qName.equals("InstanceEndpoint")) { - instanceEndpoints.add(instanceEndpointHandler.getResult()); - } else if (inInstanceEndpoints) { - instanceEndpointHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("RoleName")) { - roleName = currentOrNull(currentText); - } else if (qName.equals("InstanceName")) { - instanceName = currentOrNull(currentText); - } else if (qName.equals("InstanceStatus")) { - instanceStatus = InstanceStatus.fromString(currentOrNull(currentText)); - } else if (qName.equals("PowerState")) { - powerState = PowerState.fromString(currentOrNull(currentText)); - } else if (qName.equals("InstanceUpgradeDomain")) { - String upgradeDomain = currentOrNull(currentText); - if (upgradeDomain != null) { - instanceUpgradeDomain = Integer.parseInt(upgradeDomain); - } - } else if (qName.equals("InstanceFaultDomain")) { - String faultDomain = currentOrNull(currentText); - if (faultDomain != null) { - instanceFaultDomain = Integer.parseInt(faultDomain); - } - } else if (qName.equals("InstanceSize")) { - String size = currentOrNull(currentText); - if (size != null) { - instanceSize = RoleSize.Type.fromString(size); - } - } else if (qName.equals("IpAddress")) { - ipAddress = currentOrNull(currentText); - } else if (qName.equals("HostName")) { - hostname = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inInstanceEndpoints) { - instanceEndpointHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleSizeHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleSizeHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleSizeHandler.java deleted file mode 100644 index f343d7f..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RoleSizeHandler.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.http.functions.ParseSax; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/dn469422.aspx" >api</a> - */ -final class RoleSizeHandler extends ParseSax.HandlerForGeneratedRequestWithResult<RoleSize> { - - private RoleSize.Type name; - - private String label; - - private Integer cores; - - private Integer memoryInMb; - - private Boolean supportedByWebWorkerRoles; - - private Boolean supportedByVirtualMachines; - - private Integer maxDataDiskCount; - - private Integer webWorkerResourceDiskSizeInMb; - - private Integer virtualMachineResourceDiskSizeInMb; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public RoleSize getResult() { - return RoleSize.create(name, label, cores, memoryInMb, supportedByWebWorkerRoles, - supportedByVirtualMachines, maxDataDiskCount, webWorkerResourceDiskSizeInMb, virtualMachineResourceDiskSizeInMb); - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Name")) { - String type = currentOrNull(currentText); - name = RoleSize.Type.fromString(currentOrNull(currentText).toUpperCase()); - } else if (qName.equals("Label")) { - label = currentOrNull(currentText); - - } else if (qName.equals("Cores")) { - String coresString = currentOrNull(currentText); - if (coresString != null) { - cores = Integer.parseInt(coresString); - } - } else if (qName.equals("MemoryInMb")) { - String memoryInMbString = currentOrNull(currentText); - if (memoryInMbString != null) { - memoryInMb = Integer.parseInt(memoryInMbString); - } - } else if (qName.equals("SupportedByWebWorkerRoles")) { - String supportedByWebWorkerRolesString = currentOrNull(currentText); - if (supportedByWebWorkerRolesString != null) { - supportedByWebWorkerRoles = Boolean.valueOf(supportedByWebWorkerRolesString); - } - } else if (qName.equals("SupportedByVirtualMachines")) { - String supportedByVirtualMachinesString = currentOrNull(currentText); - if (supportedByVirtualMachinesString != null) { - supportedByVirtualMachines = Boolean.valueOf(supportedByVirtualMachinesString); - } - } else if (qName.equals("MaxDataDiskCount")) { - String maxDataDiskCountString = currentOrNull(currentText); - if (maxDataDiskCountString != null) { - maxDataDiskCount = Integer.parseInt(maxDataDiskCountString); - } - } else if (qName.equals("WebWorkerResourceDiskSizeInMb")) { - String webWorkerResourceDiskSizeInMbString = currentOrNull(currentText); - if (webWorkerResourceDiskSizeInMbString != null) { - webWorkerResourceDiskSizeInMb = Integer.parseInt(webWorkerResourceDiskSizeInMbString); - } - } else if (qName.equals("VirtualMachineResourceDiskSizeInMb")) { - String virtualMachineResourceDiskSizeInMbString = currentOrNull(currentText); - if (virtualMachineResourceDiskSizeInMbString != null) { - virtualMachineResourceDiskSizeInMb = Integer.parseInt(virtualMachineResourceDiskSizeInMbString); - } - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RuleHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RuleHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RuleHandler.java deleted file mode 100644 index 6c9229b..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/RuleHandler.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Rule; -import org.jclouds.http.functions.ParseSax; - -final class RuleHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Rule> { - - private String name; - - private Rule.Type type; - - private String priority; - - private Rule.Action action; - - private String sourceAddressPrefix; - - private String sourcePortRange; - - private String destinationAddressPrefix; - - private String destinationPortRange; - - private Rule.Protocol protocol; - - private String state; - - private Boolean isDefault; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public Rule getResult() { - Rule result = Rule.create(name, type, priority, action, sourceAddressPrefix, sourcePortRange, - destinationAddressPrefix, destinationPortRange, protocol, state, isDefault); - - name = priority = sourceAddressPrefix = sourcePortRange = destinationAddressPrefix - = destinationPortRange = state = null; // handler is called in a loop. - protocol = null; - action = null; - type = null; - isDefault = false; - return result; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("Type")) { - type = Rule.Type.fromString(currentOrNull(currentText)); - } else if (qName.equals("Priority")) { - priority = currentOrNull(currentText); - } else if (qName.equals("Action")) { - action = Rule.Action.fromString(currentOrNull(currentText)); - } else if (qName.equals("SourceAddressPrefix")) { - sourceAddressPrefix = currentOrNull(currentText); - } else if (qName.equals("SourcePortRange")) { - sourcePortRange = currentOrNull(currentText); - } else if (qName.equals("DestinationAddressPrefix")) { - destinationAddressPrefix = currentOrNull(currentText); - } else if (qName.equals("DestinationPortRange")) { - destinationPortRange = currentOrNull(currentText); - } else if (qName.equals("Protocol")) { - protocol = Rule.Protocol.fromString(currentOrNull(currentText)); - } else if (qName.equals("State")) { - state = currentOrNull(currentText); - } else if (qName.equals("IsDefault")) { - String isDefaultString = currentOrNull(currentText); - if (isDefaultString != null) { - isDefault = Boolean.valueOf(isDefaultString); - } - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ServiceCertificateHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ServiceCertificateHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ServiceCertificateHandler.java deleted file mode 100644 index 475e837..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ServiceCertificateHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import java.net.URI; -import org.jclouds.azurecompute.domain.ServiceCertificate; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >Response body description</a> - */ -public final class ServiceCertificateHandler extends ParseSax.HandlerForGeneratedRequestWithResult<ServiceCertificate> { - - private URI url; - - private String thumbprint; - - private String thumbprintAlgorithm; - - private String data; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public ServiceCertificate getResult() { - final ServiceCertificate result = ServiceCertificate.create(url, thumbprint, thumbprintAlgorithm, data); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - url = null; - thumbprint = thumbprintAlgorithm = data = null; - } - - @Override - public void startElement( - final String ignoredUri, - final String ignoredLocalName, - final String qName, - final Attributes ignoredAttributes) { - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if (qName.equals("CertificateUrl")) { - url = URI.create(currentOrNull(currentText)); - } else if (qName.equals("Thumbprint")) { - thumbprint = currentOrNull(currentText); - } else if (qName.equals("ThumbprintAlgorithm")) { - thumbprintAlgorithm = currentOrNull(currentText); - } else if (qName.equals("Data")) { - data = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceHandler.java deleted file mode 100644 index 133fefe..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceHandler.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Map; - -import org.jclouds.azurecompute.domain.StorageService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.base.Throwables; -import com.google.common.collect.Maps; -import com.google.inject.Inject; -import org.jclouds.date.DateService; - -public class StorageServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<StorageService> { - - private URL url; - - private String serviceName; - - private StorageService.StorageServiceProperties storageServiceProperties; - - private boolean inStorageServiceProperties; - - private final StorageServicePropertiesHandler storageServicePropertiesHandler; - - private final Map<String, String> extendedProperties = Maps.newHashMap(); - - private boolean inExtendedProperties; - - private final ExtendedPropertiesHandler extendedPropertiesHandler = new ExtendedPropertiesHandler(); - - private String capability; - - private final StringBuilder currentText = new StringBuilder(); - - @Inject - StorageServiceHandler(final DateService dateService) { - this.storageServicePropertiesHandler = new StorageServicePropertiesHandler(dateService); - } - - @Override - public StorageService getResult() { - final StorageService result = StorageService.create( - url, serviceName, storageServiceProperties, extendedProperties, capability); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - serviceName = null; - url = null; - storageServiceProperties = null; - extendedProperties.clear(); - capability = null; - } - - @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { - if ("StorageServiceProperties".equals(qName)) { - inStorageServiceProperties = true; - } else if (inStorageServiceProperties) { - storageServicePropertiesHandler.startElement(uri, localName, qName, attributes); - } else if ("ExtendedProperties".equals(qName)) { - inExtendedProperties = true; - } - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if ("StorageServiceProperties".equals(qName)) { - inStorageServiceProperties = false; - storageServiceProperties = storageServicePropertiesHandler.getResult(); - } else if (inStorageServiceProperties) { - storageServicePropertiesHandler.endElement(ignoredUri, ignoredName, qName); - } else if ("ExtendedProperties".equals(qName)) { - inExtendedProperties = false; - extendedProperties.putAll(extendedPropertiesHandler.getResult()); - } else if (inExtendedProperties) { - extendedPropertiesHandler.endElement(ignoredUri, ignoredName, qName); - } else if ("ServiceName".equals(qName)) { - serviceName = currentOrNull(currentText); - } else if ("Url".equals(qName)) { - final String urlText = currentOrNull(currentText); - if (urlText != null) { - try { - url = new URL(urlText); - } catch (MalformedURLException e) { - throw Throwables.propagate(e); - } - } - } else if ("Capability".equals(qName)) { - capability = currentOrNull(currentText); - } - - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - if (inStorageServiceProperties) { - storageServicePropertiesHandler.characters(ch, start, length); - } else if (inExtendedProperties) { - extendedPropertiesHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceKeysHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceKeysHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceKeysHandler.java deleted file mode 100644 index ee528aa..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServiceKeysHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import com.google.common.base.Throwables; -import java.net.MalformedURLException; -import java.net.URL; -import org.jclouds.azurecompute.domain.StorageServiceKeys; -import org.jclouds.http.functions.ParseSax; - -public class StorageServiceKeysHandler extends ParseSax.HandlerForGeneratedRequestWithResult<StorageServiceKeys> { - - private URL url; - - private String primary; - - private String secondary; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public StorageServiceKeys getResult() { - final StorageServiceKeys result = StorageServiceKeys.create(url, primary, secondary); - url = null; - primary = null; - secondary = null; - return result; - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if ("Url".equals(qName)) { - final String urlText = currentOrNull(currentText); - if (urlText != null) { - try { - url = new URL(urlText); - } catch (MalformedURLException e) { - throw Throwables.propagate(e); - } - } - } else if ("Primary".equals(qName)) { - primary = currentOrNull(currentText); - } else if ("Secondary".equals(qName)) { - secondary = currentOrNull(currentText); - } - - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServicePropertiesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServicePropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServicePropertiesHandler.java deleted file mode 100644 index 41f6236..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/StorageServicePropertiesHandler.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.io.BaseEncoding.base64; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import com.google.common.base.Throwables; -import com.google.common.collect.Lists; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Date; -import java.util.List; - -import org.jclouds.azurecompute.domain.StorageService; -import org.jclouds.azurecompute.domain.StorageService.AccountType; -import org.jclouds.azurecompute.domain.StorageService.RegionStatus; -import org.jclouds.azurecompute.domain.StorageService.Status; -import org.jclouds.date.DateService; -import org.jclouds.http.functions.ParseSax; - -import org.xml.sax.Attributes; - -public class StorageServicePropertiesHandler - extends ParseSax.HandlerForGeneratedRequestWithResult<StorageService.StorageServiceProperties> { - - private String description; - - private String affinityGroup; - - private String location; - - private String label; - - private StorageService.Status status; - - private final List<URL> endpoints = Lists.newArrayList(); - - private boolean inEndpoints; - - private String geoPrimaryRegion; - - private StorageService.RegionStatus statusOfPrimary; - - private Date lastGeoFailoverTime; - - private String geoSecondaryRegion; - - private StorageService.RegionStatus statusOfSecondary; - - private Date creationTime; - - private final List<String> customDomains = Lists.newArrayList(); - - private final List<URL> secondaryEndpoints = Lists.newArrayList(); - - private boolean inSecondaryEndpoints; - - private AccountType accountType; - - private final DateService dateService; - - private final StringBuilder currentText = new StringBuilder(); - - public StorageServicePropertiesHandler(final DateService dateService) { - this.dateService = dateService; - } - - @Override - public StorageService.StorageServiceProperties getResult() { - final StorageService.StorageServiceProperties result = StorageService.StorageServiceProperties.create( - description, affinityGroup, location, label, status, endpoints, - geoPrimaryRegion, statusOfPrimary, lastGeoFailoverTime, geoSecondaryRegion, statusOfSecondary, - creationTime, customDomains, secondaryEndpoints, accountType); - - description = affinityGroup = location = label = null; - status = null; - endpoints.clear(); - geoPrimaryRegion = null; - statusOfPrimary = null; - lastGeoFailoverTime = null; - geoSecondaryRegion = null; - statusOfSecondary = null; - creationTime = null; - customDomains.clear(); - secondaryEndpoints.clear(); - accountType = null; - - return result; - } - - @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { - if ("Endpoints".equals(qName)) { - inEndpoints = true; - } else if ("SecondaryEndpoints".equals(qName)) { - inSecondaryEndpoints = true; - } - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if ("Description".equals(qName)) { - description = currentOrNull(currentText); - } else if ("AffinityGroup".equals(qName)) { - affinityGroup = currentOrNull(currentText); - } else if ("Location".equals(qName)) { - location = currentOrNull(currentText); - } else if ("Label".equals(qName)) { - label = new String(base64().decode(currentOrNull(currentText)), UTF_8); - } else if ("Status".equals(qName)) { - status = Status.fromString(currentOrNull(currentText)); - } else if ("Endpoints".equals(qName)) { - inEndpoints = false; - } else if ("SecondaryEndpoints".equals(qName)) { - inSecondaryEndpoints = false; - } else if ("Endpoint".equals(qName)) { - final String urlText = currentOrNull(currentText); - try { - if (inEndpoints) { - endpoints.add(new URL(urlText)); - } else if (inSecondaryEndpoints) { - secondaryEndpoints.add(new URL(urlText)); - } - } catch (MalformedURLException e) { - throw Throwables.propagate(e); - } - } else if ("GeoPrimaryRegion".equals(qName)) { - geoPrimaryRegion = currentOrNull(currentText); - } else if ("StatusOfPrimary".equals(qName)) { - statusOfPrimary = RegionStatus.fromString(currentOrNull(currentText)); - } else if ("LastGeoFailoverTime".equals(qName)) { - lastGeoFailoverTime = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if ("GeoSecondaryRegion".equals(qName)) { - geoSecondaryRegion = currentOrNull(currentText); - } else if ("StatusOfSecondary".equals(qName)) { - final String text = currentOrNull(currentText); - if (text != null) { - statusOfSecondary = RegionStatus.fromString(text); - } - } else if ("CreationTime".equals(qName)) { - creationTime = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if ("Name".equals(qName)) { - final String text = currentOrNull(currentText); - if (text != null) { - customDomains.add(text); - } - } else if ("AccountType".equals(qName)) { - accountType = AccountType.fromString(currentOrNull(currentText)); - } - - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetHandler.java deleted file mode 100644 index c60f610..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.NetworkConfiguration.Subnet; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public class SubnetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Subnet> { - - private String name; - - private String addressPrefix; - - private String networkSecurityGroup; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equalsIgnoreCase("Subnet")) { - name = attributes.getValue("name"); - } - } - - @Override - public Subnet getResult() { - Subnet result = Subnet.create(name, addressPrefix, networkSecurityGroup); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = addressPrefix = null; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("AddressPrefix")) { - addressPrefix = currentOrNull(currentText); - } else if (qName.equals("NetworkSecurityGroup")) { - networkSecurityGroup = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetNameHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetNameHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetNameHandler.java deleted file mode 100644 index 3853478..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/SubnetNameHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public class SubnetNameHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Role.ConfigurationSet.SubnetName> { - - private String name; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - } - - @Override - public Role.ConfigurationSet.SubnetName getResult() { - Role.ConfigurationSet.SubnetName result = Role.ConfigurationSet.SubnetName.create(name); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = null; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("SubnetName")) { - name = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VMImageHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VMImageHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VMImageHandler.java deleted file mode 100644 index 9812018..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VMImageHandler.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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.azurecompute.xml; - -import com.google.common.collect.Lists; -import com.google.inject.Inject; -import org.jclouds.azurecompute.domain.DataVirtualHardDisk; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.azurecompute.domain.VMImage; -import org.jclouds.date.DateService; -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import java.net.URI; -import java.util.Date; -import java.util.List; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -/** - * @see <a href="https://msdn.microsoft.com/en-us/library/azure/dn499770.aspx" >api</a> - */ -final class VMImageHandler extends ParseSax.HandlerForGeneratedRequestWithResult<VMImage> { - private String name; - private String label; - private String category; - private String description; - private VMImage.OSDiskConfiguration osDiskConfiguration; - private String serviceName; - private String deploymentName; - private String roleName; - private String location; - private String affinityGroup; - private Date createdTime; - private Date modifiedTime; - private String language; - private String imageFamily; - private RoleSize.Type recommendedVMSize; - private Boolean isPremium; - private String eula; - private URI iconUri; - private URI smallIconUri; - private URI privacyUri; - private Date publishedDate; - - private final StringBuilder currentText = new StringBuilder(); - - private final DataVirtualHardDiskHandler dataVirtualHardDiskHandler; - private final OSConfigHandler osConfigHandler; - private List<DataVirtualHardDisk> dataDiskConfigurations = Lists.newArrayList(); - - private boolean inOSConfig; - private boolean inDataConfig; - private final DateService dateService = new SimpleDateFormatDateService(); - - @Inject VMImageHandler(DataVirtualHardDiskHandler dataVirtualHardDiskHandler, OSConfigHandler osConfigHandler) { - this.dataVirtualHardDiskHandler = dataVirtualHardDiskHandler; - this.osConfigHandler = osConfigHandler; - } - - @Override - public VMImage getResult() { - VMImage result = VMImage - .create(name, label, category, description, osDiskConfiguration, dataDiskConfigurations, - serviceName, deploymentName, roleName, location, affinityGroup, createdTime, modifiedTime, language, - imageFamily, recommendedVMSize, isPremium, eula, iconUri, smallIconUri, privacyUri, publishedDate); - resetState(); // handler is called in a loop. - return result; - } - - @Override - public void startElement(String ignoredUri, String ignoredLocalName, String qName, - Attributes ignoredAttributes) throws SAXException { - - if (qName.equals("OSDiskConfiguration")) { - inOSConfig = true; - } - if (inOSConfig) { - osConfigHandler.endElement(ignoredUri, ignoredLocalName, qName); - } - if (qName.equals("DataDiskConfiguration")) { - inDataConfig = true; - } - if (inDataConfig) { - dataVirtualHardDiskHandler.startElement(ignoredUri, ignoredLocalName, qName, ignoredAttributes); - } - } - - private void resetState() { - name = affinityGroup = label = description = category = null; - serviceName = deploymentName = roleName = location = affinityGroup = null; - createdTime = modifiedTime = null; - language = imageFamily = eula = null; - recommendedVMSize = null; - isPremium = Boolean.FALSE; - iconUri = smallIconUri = privacyUri = null; - publishedDate = null; - osDiskConfiguration = null; - dataDiskConfigurations = Lists.newArrayList(); - } - - @Override public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Name") && !inDataConfig && !inOSConfig) { - name = currentOrNull(currentText); - } else if (qName.equals("Label")) { - label = currentOrNull(currentText); - } else if (qName.equals("Category")) { - category = currentOrNull(currentText); - } else if (qName.equals("Description")) { - description = currentOrNull(currentText); - } else if (qName.equals("OSDiskConfiguration")) { - osDiskConfiguration = osConfigHandler.getResult(); - inOSConfig = false; - } else if (inOSConfig) { - osConfigHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("DataDiskConfiguration") && !inOSConfig) { - dataDiskConfigurations.add(dataVirtualHardDiskHandler.getResult()); - inDataConfig = false; - } else if (inDataConfig) { - dataVirtualHardDiskHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("ServiceName")) { - serviceName = currentOrNull(currentText); - } else if (qName.equals("DeploymentName")) { - deploymentName = currentOrNull(currentText); - } else if (qName.equals("RoleName")) { - roleName = currentOrNull(currentText); - } else if (qName.equals("Location")) { - location = currentOrNull(currentText); - } else if (qName.equals("AffinityGroup")) { - affinityGroup = currentOrNull(currentText); - } else if (qName.equals("CreatedTime")) { - createdTime = dateService.iso8601DateOrSecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("ModifiedTime")) { - modifiedTime = dateService.iso8601DateOrSecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("Language")) { - language = currentOrNull(currentText); - } else if (qName.equals("ImageFamily")) { - imageFamily = currentOrNull(currentText); - } else if (qName.equals("Label")) { - label = currentOrNull(currentText); - } else if (qName.equals("RecommendedVMSize")) { - String vmSizeText = currentOrNull(currentText); - if (vmSizeText != null) { - recommendedVMSize = parseRoleSize(vmSizeText); - } - } else if (qName.equals("IconUri")) { - String uri = currentOrNull(currentText); - if (uri != null) { - iconUri = URI.create(uri); - } - } else if (qName.equals("SmallIconUri")) { - String uri = currentOrNull(currentText); - if (uri != null) { - smallIconUri = URI.create(uri); - } - } else if (qName.equals("PrivacyUri")) { - String uri = currentOrNull(currentText); - if (uri != null) { - privacyUri = URI.create(uri); - } - } else if (qName.equals("IsPremium")) { - String isPremiumText = currentOrNull(currentText); - if (isPremiumText != null) { - isPremium = Boolean.parseBoolean(isPremiumText); - } - } else if (qName.equals("Eula")) { - eula = currentOrNull(currentText); - } else if (qName.equals("PublishedDate")) { - publishedDate = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } - currentText.setLength(0); - } - - @Override public void characters(char[] ch, int start, int length) { - if (inDataConfig) { - dataVirtualHardDiskHandler.characters(ch, start, length); - } else if (inOSConfig) { - osConfigHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - - private static RoleSize.Type parseRoleSize(String roleSize) { - try { - return RoleSize.Type.valueOf(roleSize.toUpperCase().replace(" ", "")); - } catch (IllegalArgumentException e) { - return RoleSize.Type.UNRECOGNIZED; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualIPHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualIPHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualIPHandler.java deleted file mode 100644 index 0ce1b52..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualIPHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Deployment.VirtualIP; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public final class VirtualIPHandler extends ParseSax.HandlerForGeneratedRequestWithResult<VirtualIP> { - - private String address; - - private Boolean isDnsProgrammed; - - private String name; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - } - - @Override - public VirtualIP getResult() { - VirtualIP result = VirtualIP.create(address, isDnsProgrammed, name); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = address = null; - isDnsProgrammed = null; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Address")) { - address = currentOrNull(currentText); - } else if (qName.equals("IsDnsProgrammed")) { - String dnsProgrammed = currentOrNull(currentText); - if (dnsProgrammed != null) { - isDnsProgrammed = Boolean.valueOf(dnsProgrammed); - } - } else if (qName.equals("Name")) { - name = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkConfigurationHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkConfigurationHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkConfigurationHandler.java deleted file mode 100644 index 2f6d11f..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkConfigurationHandler.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; -import java.util.List; - -import org.jclouds.azurecompute.domain.NetworkConfiguration; -import org.jclouds.azurecompute.domain.NetworkConfiguration.VirtualNetworkConfiguration; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; - -public class VirtualNetworkConfigurationHandler extends ParseSax.HandlerForGeneratedRequestWithResult<VirtualNetworkConfiguration> { - - private String dns; - - private List<NetworkConfiguration.VirtualNetworkSite> virtualNetworkSites = Lists.newArrayList(); - - private boolean inVirtualNetworkSite; - - private final VirtualNetworkSiteHandler virtualNetworkSiteHandler = new VirtualNetworkSiteHandler(); - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String url, String name, String qName, Attributes attributes) { - if (qName.equals("VirtualNetworkSite")) { - inVirtualNetworkSite = true; - } - if (inVirtualNetworkSite) { - virtualNetworkSiteHandler.startElement(url, name, qName, attributes); - } - } - - @Override - public VirtualNetworkConfiguration getResult() { - return VirtualNetworkConfiguration.create(dns, virtualNetworkSites); - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Dns")) { - dns = currentOrNull(currentText); - } else if (qName.equals("VirtualNetworkSites")) { - inVirtualNetworkSite = false; - } else if (qName.equals("VirtualNetworkSite")) { - virtualNetworkSites.add(virtualNetworkSiteHandler.getResult()); - } else if (inVirtualNetworkSite) { - virtualNetworkSiteHandler.endElement(ignoredUri, ignoredName, qName); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inVirtualNetworkSite) { - virtualNetworkSiteHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkSiteHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkSiteHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkSiteHandler.java deleted file mode 100644 index dd9c7ee..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/VirtualNetworkSiteHandler.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; -import java.util.List; - -import org.jclouds.azurecompute.domain.NetworkConfiguration.AddressSpace; -import org.jclouds.azurecompute.domain.NetworkConfiguration.Subnet; -import org.jclouds.azurecompute.domain.NetworkConfiguration.VirtualNetworkSite; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; - -public class VirtualNetworkSiteHandler extends ParseSax.HandlerForGeneratedRequestWithResult<VirtualNetworkSite> { - - private String id; - - private String name; - - private String location; - - private AddressSpace addressSpace; - - private List<Subnet> subnets = Lists.newArrayList(); - - private boolean inSubnet; - - private boolean inAddressSpace; - - private final SubnetHandler subnetHandler = new SubnetHandler(); - - private final AddressSpaceHandler addressSpaceHandler = new AddressSpaceHandler(); - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equalsIgnoreCase("VirtualNetworkSite")) { - name = attributes.getValue("name"); - location = attributes.getValue("Location"); - } - - if (qName.equals("AddressSpace")) { - inAddressSpace = true; - } else if (qName.equals("Subnet")) { - inSubnet = true; - } - if (inAddressSpace) { - addressSpaceHandler.startElement(uri, name, qName, attributes); - } - if (inSubnet) { - subnetHandler.startElement(uri, name, qName, attributes); - } - } - - private void resetState() { - id = name = location = null; - subnets = Lists.newArrayList(); - addressSpace = null; - } - - @Override - public VirtualNetworkSite getResult() { - VirtualNetworkSite result = VirtualNetworkSite.create(id, name, location, addressSpace, subnets); - resetState(); // handler is called in a loop. - return result; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("AddressSpace")) { - inAddressSpace = false; - addressSpace = addressSpaceHandler.getResult(); - } else if (inAddressSpace) { - addressSpaceHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("Subnet")) { - inSubnet = false; - subnets.add(subnetHandler.getResult()); - } else if (inSubnet) { - subnetHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("Id")) { - id = currentOrNull(currentText); - } else if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("Location")) { - location = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inAddressSpace) { - addressSpaceHandler.characters(ch, start, length); - } else if (inSubnet) { - subnetHandler.characters(ch, start, length); - } else if (!inAddressSpace && !inSubnet) { - currentText.append(ch, start, length); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/AzureComputeProviderMetadataTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/AzureComputeProviderMetadataTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/AzureComputeProviderMetadataTest.java deleted file mode 100644 index a7e7eb7..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/AzureComputeProviderMetadataTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.azurecompute; - -import org.jclouds.providers.internal.BaseProviderMetadataTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "AzureManagementProviderMetadataTest") -public class AzureComputeProviderMetadataTest extends BaseProviderMetadataTest { - - public AzureComputeProviderMetadataTest() { - super(new AzureComputeProviderMetadata(), new AzureManagementApiMetadata()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/AzureTestUtils.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/AzureTestUtils.java b/azurecompute/src/test/java/org/jclouds/azurecompute/AzureTestUtils.java deleted file mode 100644 index 029c6d2..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/AzureTestUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.azurecompute; - -import com.google.common.base.Predicate; -import java.util.ArrayList; -import java.util.List; -import org.jclouds.azurecompute.domain.NetworkConfiguration; -import org.jclouds.azurecompute.features.VirtualNetworkApi; - -public class AzureTestUtils { - - public static List<NetworkConfiguration.VirtualNetworkSite> getVirtualNetworkSite(AzureComputeApi api) { - final VirtualNetworkApi vnapi = api.getVirtualNetworkApi(); - final NetworkConfiguration netConf = vnapi.getNetworkConfiguration(); - - return netConf == null - ? new ArrayList<NetworkConfiguration.VirtualNetworkSite>() - : new ArrayList<NetworkConfiguration.VirtualNetworkSite>(netConf.virtualNetworkConfiguration(). - virtualNetworkSites()); - - } - - public static class SameVirtualNetworkSiteNamePredicate - implements Predicate<NetworkConfiguration.VirtualNetworkSite> { - - private final String virtualNetworkSiteName; - - public SameVirtualNetworkSiteNamePredicate(final String virtualNetworkSiteName) { - this.virtualNetworkSiteName = virtualNetworkSiteName; - } - - @Override - public boolean apply(final NetworkConfiguration.VirtualNetworkSite input) { - return input.name().equals(virtualNetworkSiteName); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/binders/DeploymentParamsToXMLTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/binders/DeploymentParamsToXMLTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/binders/DeploymentParamsToXMLTest.java deleted file mode 100644 index cc21a98..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/binders/DeploymentParamsToXMLTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.azurecompute.binders; - -import static org.testng.Assert.assertEquals; -import java.net.URI; - -import org.jclouds.azurecompute.domain.DeploymentParams; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code DeploymentParamsToXML} - */ -@Test(groups = "unit") -public class DeploymentParamsToXMLTest { - Injector injector = Guice.createInjector(); - DeploymentParamsToXML binder = injector - .getInstance(DeploymentParamsToXML.class); - - public void testDeploymentParamsToXmlString() { - DeploymentParams.Builder paramsBuilder = DeploymentParams.builder() - .name("name") - .os(OSImage.Type.LINUX) - .username("loginUser") - .password("loginPassword") - .sourceImageName("sourceImageName") - .mediaLink(URI.create("http://medialink")) - .size(RoleSize.Type.BASIC_A0) - .externalEndpoints(ImmutableSet.of(DeploymentParams.ExternalEndpoint.inboundTcpToLocalPort(22, 22))) - .virtualNetworkName("virtualNetworkName") - .reservedIPName("reservedIPName") - .subnetNames(ImmutableList.of("subnetName")); - - HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost") - .addFormParam("InstanceId", "i-foo").build(); - request = binder.bindToRequest(request, paramsBuilder.build()); - assertEquals( - request.getPayload().getRawContent(), - "<Deployment xmlns=\"http://schemas.microsoft.com/windowsazure\"><Name>name</Name><DeploymentSlot>Production</DeploymentSlot><Label>name</Label><RoleList><Role><RoleName>name</RoleName><RoleType>PersistentVMRole</RoleType><ConfigurationSets><ConfigurationSet><ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType><HostName>name</HostName><UserName>loginUser</UserName><UserPassword>loginPassword</UserPassword><DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication><SSH><PublicKeys/><KeyPairs/></SSH></ConfigurationSet><ConfigurationSet><ConfigurationSetType>NetworkConfiguration</ConfigurationSetType><InputEndpoints><InputEndpoint><LocalPort>22</LocalPort><Name>tcp_22-22</Name><Port>22</Port><Protocol>tcp</Protocol></InputEndpoint></InputEndpoints><SubnetNames><SubnetName>subnetName</SubnetName></SubnetNames></ConfigurationSet></ConfigurationSets><DataVirtualHardDisks/><OSVirtualHardDisk><HostCaching>ReadWrite</HostCaching><MediaLink>htt p://medialink</MediaLink><SourceImageName>sourceImageName</SourceImageName><OS>Linux</OS></OSVirtualHardDisk><RoleSize>Basic_A0</RoleSize></Role></RoleList><VirtualNetworkName>virtualNetworkName</VirtualNetworkName><ReservedIPName>reservedIPName</ReservedIPName></Deployment>"); - } - -}
