From 428a9ea91cefc1aae1be892bed8c6dc8afc81069 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Wed, 6 Jan 2016 12:52:38 +0000 Subject: [PATCH 1/7] exceptions changes --- pom.xml | 8 +- .../cloud/vcloud/compute/DiskSupport.java | 24 +- .../cloud/vcloud/compute/TemplateSupport.java | 47 ++- .../cloud/vcloud/compute/vAppSupport.java | 83 +++--- .../vcloud/network/HybridVLANSupport.java | 48 +-- .../dasein/cloud/vcloud/vCloudException.java | 25 +- .../org/dasein/cloud/vcloud/vCloudMethod.java | 279 +++++++++++++----- 7 files changed, 327 insertions(+), 187 deletions(-) diff --git a/pom.xml b/pom.xml index 4170d41..78a5ce4 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.dasein dasein-cloud-vcloud - 2016.02.1-SNAPSHOT + 1.0.1-SNAPSHOT Dasein Cloud vCloud Dasein Cloud implementation for the vCloud API @@ -55,7 +55,7 @@ org.dasein dasein-cloud-core - 2016.02.1-SNAPSHOT + 1.0.1-SNAPSHOT compile false @@ -69,7 +69,7 @@ org.apache.httpcomponents httpclient - 4.2.1 + 4.5.1 log4j @@ -92,7 +92,7 @@ org.dasein dasein-cloud-test - 2016.02.1-SNAPSHOT + 1.0.1-SNAPSHOT test false diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java index caec619..00df955 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java @@ -19,13 +19,15 @@ package org.dasein.cloud.vcloud.compute; import org.apache.log4j.Logger; +import org.dasein.cloud.CloudErrorType; import org.dasein.cloud.CloudException; +import org.dasein.cloud.GeneralCloudException; import org.dasein.cloud.InternalException; import org.dasein.cloud.OperationNotSupportedException; +import org.dasein.cloud.ResourceNotFoundException; import org.dasein.cloud.ResourceStatus; import org.dasein.cloud.Tag; import org.dasein.cloud.compute.AbstractVolumeSupport; -import org.dasein.cloud.compute.Platform; import org.dasein.cloud.compute.Volume; import org.dasein.cloud.compute.VolumeCreateOptions; import org.dasein.cloud.compute.VolumeFormat; @@ -37,7 +39,8 @@ import org.dasein.cloud.vcloud.vCloud; import org.dasein.cloud.vcloud.vCloudMethod; import org.dasein.util.CalendarWrapper; -import org.dasein.util.uom.storage.*; +import org.dasein.util.uom.storage.Gigabyte; +import org.dasein.util.uom.storage.Storage; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -46,7 +49,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.HashMap; -import java.util.Locale; import java.util.Map; /** @@ -109,17 +111,19 @@ public void attach(@Nonnull String volumeId, @Nonnull String toServer, @Nonnull String response = method.post(vCloudMethod.CREATE_DISK, vdcId, xml.toString()); if( response.length() < 1 ) { - throw new CloudException("No error, but no volume"); + throw new GeneralCloudException("No error, but no volume", CloudErrorType.GENERAL); } Document doc = method.parseXML(response); String docElementTagName = doc.getDocumentElement().getTagName(); String nsString = ""; - if(docElementTagName.contains(":"))nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1); + if(docElementTagName.contains(":")) { + nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1); + } NodeList disks = doc.getElementsByTagName(nsString + "Disk"); if( disks.getLength() < 1 ) { - throw new CloudException("No error, but no volume"); + throw new GeneralCloudException("No error, but no volume", CloudErrorType.GENERAL); } Node disk = disks.item(0); Node href = disk.getAttributes().getNamedItem("href"); @@ -164,7 +168,7 @@ public void attach(@Nonnull String volumeId, @Nonnull String toServer, @Nonnull } return volumeId; } - throw new CloudException("No ID provided in Disk XML"); + throw new GeneralCloudException("No ID provided in Disk XML", CloudErrorType.GENERAL); } finally { APITrace.end(); @@ -178,12 +182,14 @@ public void detach(@Nonnull String volumeId, boolean force) throws InternalExcep Volume volume = getVolume(volumeId); if( volume == null ) { - throw new CloudException("No such volume: " + volumeId); + throw new ResourceNotFoundException("No such volume: " + volumeId); } String serverId = volume.getProviderVirtualMachineId(); if( serverId == null ) { - throw new CloudException("No virtual machine is attached to this volume"); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("No virtual machine is attached to this volume"); } vCloudMethod method = new vCloudMethod(getProvider()); StringBuilder xml = new StringBuilder(); diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java index 00f9ab4..6199254 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java @@ -20,8 +20,11 @@ import org.apache.log4j.Logger; import org.dasein.cloud.AsynchronousTask; +import org.dasein.cloud.CloudErrorType; import org.dasein.cloud.CloudException; +import org.dasein.cloud.GeneralCloudException; import org.dasein.cloud.InternalException; +import org.dasein.cloud.ResourceNotFoundException; import org.dasein.cloud.Tag; import org.dasein.cloud.compute.AbstractImageSupport; import org.dasein.cloud.compute.Architecture; @@ -32,7 +35,6 @@ import org.dasein.cloud.compute.MachineImage; import org.dasein.cloud.compute.MachineImageFormat; import org.dasein.cloud.compute.MachineImageState; -import org.dasein.cloud.compute.MachineImageType; import org.dasein.cloud.compute.Platform; import org.dasein.cloud.compute.VirtualMachine; import org.dasein.cloud.compute.VmState; @@ -107,22 +109,24 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As String vmId = options.getVirtualMachineId(); if( vmId == null ) { - throw new CloudException("A capture operation requires a valid VM ID"); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("A capture operation requires a valid VM ID"); } VirtualMachine vm = ((vCloud)getProvider()).getComputeServices().getVirtualMachineSupport().getVirtualMachine(vmId); String vAppId = (vm == null ? null : (String)vm.getTag(vAppSupport.PARENT_VAPP_ID)); if( vm == null ) { - throw new CloudException("No such virtual machine: " + vmId); + throw new ResourceNotFoundException("No such virtual machine: " + vmId); } else if( vAppId == null ) { - throw new CloudException("Unable to determine virtual machine vApp for capture: " + vmId); + throw new ResourceNotFoundException("Unable to determine virtual machine vApp for capture: " + vmId); } long timeout = (System.currentTimeMillis() + CalendarWrapper.MINUTE * 10L); while( timeout > System.currentTimeMillis() ) { if( vm == null ) { - throw new CloudException("VM " + vmId + " went away"); + throw new ResourceNotFoundException("VM " + vmId + " went away"); } if( !vm.getCurrentState().equals(VmState.PENDING) ) { break; @@ -151,7 +155,7 @@ else if( vAppId == null ) { String response = method.post(vCloudMethod.CAPTURE_VAPP, vm.getProviderDataCenterId(), xml.toString()); if( response.equals("") ) { - throw new CloudException("No error or other information was in the response"); + throw new GeneralCloudException("No error or other information was in the response", CloudErrorType.GENERAL); } Document doc = method.parseXML(response); @@ -163,7 +167,7 @@ else if( vAppId == null ) { logger.warn("The cloud thinks the vApp or VM is still running; going to check what's going on: " + e.getMessage()); vm = ((vCloud)getProvider()).getComputeServices().getVirtualMachineSupport().getVirtualMachine(vmId); if( vm == null ) { - throw new CloudException("Virtual machine went away"); + throw new ResourceNotFoundException("Virtual machine went away"); } if( !vm.getCurrentState().equals(VmState.STOPPED) ) { logger.warn("Current state of VM: " + vm.getCurrentState()); @@ -171,7 +175,7 @@ else if( vAppId == null ) { } response = method.post(vCloudMethod.CAPTURE_VAPP, vm.getProviderDataCenterId(), xml.toString()); if( response.equals("") ) { - throw new CloudException("No error or other information was in the response"); + throw new GeneralCloudException("No error or other information was in the response", CloudErrorType.GENERAL); } doc = method.parseXML(response); method.checkError(doc); @@ -184,7 +188,7 @@ else if( vAppId == null ) { NodeList vapps = doc.getElementsByTagName("VAppTemplate"); if( vapps.getLength() < 1 ) { - throw new CloudException("No vApp templates were found in response"); + throw new ResourceNotFoundException("No vApp templates were found in response"); } Node vapp = vapps.item(0); String imageId = null; @@ -194,12 +198,12 @@ else if( vAppId == null ) { imageId = ((vCloud)getProvider()).toID(href.getNodeValue().trim()); } if( imageId == null || imageId.length() < 1 ) { - throw new CloudException("No imageId was found in response"); + throw new ResourceNotFoundException("No imageId was found in response"); } MachineImage img = loadVapp(imageId, getContext().getAccountNumber(), false, options.getName(), options.getDescription(), System.currentTimeMillis()); if( img == null ) { - throw new CloudException("Image was lost"); + throw new ResourceNotFoundException("Image was lost"); } method.waitFor(response); publish(img); @@ -258,11 +262,11 @@ private void publish(@Nonnull MachineImage img) throws CloudException, InternalE } } if( href == null ) { - throw new CloudException("No catalog could be identified for publishing vApp template " + img.getProviderMachineImageId()); + throw new ResourceNotFoundException("No catalog could be identified for publishing vApp template " + img.getProviderMachineImageId()); } c = getCatalog(false, href); if( c == null ) { - throw new CloudException("No catalog could be identified for publishing vApp template " + img.getProviderMachineImageId()); + throw new ResourceNotFoundException("No catalog could be identified for publishing vApp template " + img.getProviderMachineImageId()); } } @@ -1012,7 +1016,7 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C MachineImage image = getImage(providerImageId); if( image == null ) { - throw new CloudException("No such image: " + providerImageId); + throw new ResourceNotFoundException("No such image: " + providerImageId); } vCloudMethod method = new vCloudMethod((vCloud)getProvider()); String catalogItemId = (String)image.getTag("catalogItemId"); @@ -1096,21 +1100,6 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C } } - @Override - public boolean supportsCustomImages() { - return true; - } - - @Override - public boolean supportsImageCapture(@Nonnull MachineImageType type) { - return type.equals(MachineImageType.VOLUME); - } - - @Override - public boolean supportsPublicLibrary(@Nonnull ImageClass cls) { - return cls.equals(ImageClass.MACHINE); - } - @Override public void setTags(@Nonnull String imageId, @Nonnull Tag... tags) throws CloudException, InternalException { APITrace.begin(getProvider(), "Image.setTags"); diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java index b32f0b0..7c7770e 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java @@ -19,9 +19,13 @@ package org.dasein.cloud.vcloud.compute; import org.apache.log4j.Logger; +import org.dasein.cloud.CloudErrorType; import org.dasein.cloud.CloudException; +import org.dasein.cloud.GeneralCloudException; import org.dasein.cloud.InternalException; +import org.dasein.cloud.ResourceNotFoundException; import org.dasein.cloud.Tag; +import org.dasein.cloud.TaskInProgressException; import org.dasein.cloud.compute.AbstractVMSupport; import org.dasein.cloud.compute.Architecture; import org.dasein.cloud.compute.MachineImage; @@ -149,7 +153,14 @@ public VirtualMachineCapabilities getCapabilities() throws InternalException, Cl public @Nullable VirtualMachineProduct getProduct(@Nonnull String productId) throws InternalException, CloudException { APITrace.begin(getProvider(), "VM.getProduct"); try { - VirtualMachineProduct product = super.getProduct(productId); + VirtualMachineProduct product = null; + + Iterable list = listAllProducts(); + for (VirtualMachineProduct p : list) { + if (p.getProviderProductId().equals(productId)) { + product = p; + } + } if( product == null && productId.startsWith("custom") ) { String[] parts = productId.split(":"); @@ -290,7 +301,9 @@ public boolean isSubscribed() throws CloudException, InternalException { final String fullname = withLaunchOptions.getHostName(); final String basename = validateHostName(withLaunchOptions.getHostName()); if (basename.length() > 27) { - throw new CloudException("The maximum name length is 27: '" + basename + "' is " + basename.length()); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("The maximum name length is 27: '" + basename + "' is " + basename.length()); } String vdcId = withLaunchOptions.getDataCenterId(); @@ -304,14 +317,14 @@ public boolean isSubscribed() throws CloudException, InternalException { } } if( vdcId == null ) { - throw new CloudException("Unable to identify a target data center for deploying VM"); + throw new ResourceNotFoundException("Unable to identify a target data center for deploying VM"); } final VirtualMachineProduct product = getProduct(withLaunchOptions.getStandardProductId()); final vCloudMethod method = new vCloudMethod(getProvider()); final MachineImage img = getProvider().getComputeServices().getImageSupport().getImage(withLaunchOptions.getMachineImageId()); if( img == null ) { - throw new CloudException("No such image: " + withLaunchOptions.getMachineImageId()); + throw new ResourceNotFoundException("No such image: " + withLaunchOptions.getMachineImageId()); } StringBuilder xml = new StringBuilder(); @@ -334,12 +347,12 @@ public boolean isSubscribed() throws CloudException, InternalException { } } if (vlanId == null) { - throw new CloudException("Could not locate default vlan '" + defaultVlanName + "'"); + throw new ResourceNotFoundException("Could not locate default vlan '" + defaultVlanName + "'"); } } else if (defaultVlanNameDHCP != null && !defaultVlanNameDHCP.trim().isEmpty()) { - throw new CloudException("No vlan selected and the default is DHCP-based which is not supported"); + throw new GeneralCloudException("No vlan selected and the default is DHCP-based which is not supported", CloudErrorType.GENERAL); } else { - throw new CloudException("No vlan specified and no default."); + throw new GeneralCloudException("No vlan specified and no default.", CloudErrorType.GENERAL); } } @@ -382,7 +395,7 @@ public boolean isSubscribed() throws CloudException, InternalException { } } if (parentId == null || parentHref == null) { - throw new CloudException("Unable to find the network config settings - cannot specify network for this vApp"); + throw new ResourceNotFoundException("Unable to find the network config settings - cannot specify network for this vApp"); } } @@ -421,7 +434,7 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString xml.append(""); } else { - throw new CloudException("Failed to find vlan " + vlanId); + throw new ResourceNotFoundException("Failed to find vlan " + vlanId); } xml.append("true"); xml.append(""); @@ -441,7 +454,7 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString method.waitFor(instantiateResponse); } catch (CloudException e) { logger.error("Error waiting for " + vCloudMethod.INSTANTIATE_VAPP + " task to complete", e); - throw new CloudException("Error waiting for " + vCloudMethod.INSTANTIATE_VAPP + " task to complete"); + throw new TaskInProgressException("Error waiting for " + vCloudMethod.INSTANTIATE_VAPP + " task to complete"); } Document composeDoc = method.parseXML(instantiateResponse); @@ -456,7 +469,7 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString NodeList vapps = composeDoc.getElementsByTagName(nsString + "VApp"); if( vapps.getLength() < 1 ) { - throw new CloudException("The instantiation operation succeeded, but no vApp was present"); + throw new GeneralCloudException("The instantiation operation succeeded, but no vApp was present", CloudErrorType.GENERAL); } Node vapp = vapps.item(0); Node href = vapp.getAttributes().getNamedItem("href"); @@ -472,7 +485,7 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString } catch( Throwable t ) { logger.error("Problem backing out after vApp went away: " + t.getMessage()); } - throw new CloudException("vApp went away"); + throw new ResourceNotFoundException("vApp went away: "+vappId); } final Document doc = method.parseXML(vAppResponse); @@ -489,7 +502,9 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString } catch (Throwable t) { logger.error("Problem cleaning up vApp " + vappId + ": " + t.getMessage()); } - throw new CloudException("Because there are multiple VMs in this vApp, the maximum name length is 25: '" + basename + "' is " + basename.length()); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("Because there are multiple VMs in this vApp, the maximum name length is 25: '" + basename + "' is " + basename.length()); } if (fullname.length() > 126) { try { @@ -498,14 +513,20 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString } catch (Throwable t) { logger.error("Problem cleaning up vApp " + vappId + ": " + t.getMessage()); } - throw new CloudException("Because there are multiple VMs in this vApp, the maximum name length is 126: '" + basename + "' is " + basename.length()); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("Because there are multiple VMs in this vApp, the maximum name length is 126: '" + basename + "' is " + basename.length()); } } else if (basename.length() > 27) { // should have been rejected already - throw new CloudException("The maximum name length is 27: '" + basename + "' is " + basename.length()); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("The maximum name length is 27: '" + basename + "' is " + basename.length()); } else if (fullname.length() > 128) { - throw new CloudException("The maximum name length is 128: '" + basename + "' is " + basename.length()); + //todo + //should we have a new exception for errors caused by user/client provided data? + throw new InternalException("The maximum name length is 128: '" + basename + "' is " + basename.length()); } String vmId = parseVmId(vmNodes); @@ -521,7 +542,7 @@ else if (fullname.length() > 128) { } catch( Throwable t ) { logger.error("Problem backing out after no virtual machines exist in response: " + t.getMessage()); } - throw new CloudException("No virtual machines exist in response"); + throw new GeneralCloudException("No virtual machines exist in response", CloudErrorType.GENERAL); } } VirtualMachine vm = getVirtualMachine(vmId); @@ -533,7 +554,7 @@ else if (fullname.length() > 128) { } catch( Throwable t ) { logger.error("Problem backing out after failing to identify VM in response: " + t.getMessage()); } - throw new CloudException("Unable to identify VM " + vmId + "."); + throw new ResourceNotFoundException("Unable to identify VM " + vmId + "."); } final String fvmId = vmId; @@ -1058,22 +1079,6 @@ public Iterable listProducts(@Nonnull String providerMach } } - @Override - public Iterable listSupportedArchitectures() throws InternalException, CloudException { - Cache cache = Cache.getInstance(getProvider(), "architectures", Architecture.class, CacheLevel.CLOUD); - Iterable list = cache.get(getContext()); - - if( list == null) { - ArrayList a = new ArrayList(); - - a.add(Architecture.I32); - a.add(Architecture.I64); - list = a; - cache.put(getContext(), Collections.unmodifiableList(a)); - } - return list; - } - @Override public @Nonnull Iterable listVirtualMachines() throws InternalException, CloudException { getProvider().hold(); @@ -1334,7 +1339,7 @@ private void stopVappOrVm(@Nonnull String id, boolean force) throws CloudExcepti vCloudMethod method = new vCloudMethod(getProvider()); String xml = method.get("vApp", id); if (xml == null) { - throw new CloudException("No information returned for ID: " + id); + throw new ResourceNotFoundException("No information returned for ID: " + id); } Document doc = method.parseXML(xml); String docElementTagName = doc.getDocumentElement().getTagName(); @@ -1356,7 +1361,7 @@ private void stopVappOrVm(@Nonnull String id, boolean force) throws CloudExcepti // 2. It's a VM. Find vApp ID String vAppId = parseParentVappId(nodes, method); if (vAppId == null) { - throw new CloudException("No parent vApp ID found for: " + id); + throw new ResourceNotFoundException("No parent vApp ID found for: " + id); } // 3. Does the vApp contain multiple VMs? @@ -1371,7 +1376,7 @@ private void stopVappOrOneVm(String vAppId, String vmId, boolean force) throws C vCloudMethod method = new vCloudMethod(getProvider()); String xml = method.get("vApp", vAppId); if (xml == null) { - throw new CloudException("No information returned for ID: " + vAppId); + throw new ResourceNotFoundException("No information returned for ID: " + vAppId); } Document doc = method.parseXML(xml); @@ -1412,7 +1417,7 @@ private void stopVappOrOneVm(String vAppId, String vmId, boolean force) throws C // 4b. If the vApp contains just one VM, undeploy the vApp undeploy(vAppId, powerAction); } else { - throw new CloudException("Expected at least one VM"); + throw new ResourceNotFoundException("Expected at least one VM"); } } @@ -1571,7 +1576,7 @@ public void terminate(@Nonnull String vmId) throws InternalException, CloudExcep VirtualMachine vm = getVirtualMachine(vmId); if( vm == null ) { - throw new CloudException("No such virtual machine: " + vmId); + throw new ResourceNotFoundException("No such virtual machine: " + vmId); } String vappId = (String)vm.getTag(PARENT_VAPP_ID); Jiterator vms = new Jiterator(); diff --git a/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java b/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java index 596c353..2fbdac8 100644 --- a/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java @@ -20,10 +20,14 @@ import org.dasein.cloud.CloudException; import org.dasein.cloud.InternalException; -import org.dasein.cloud.OperationNotSupportedException; import org.dasein.cloud.Tag; import org.dasein.cloud.dc.DataCenter; -import org.dasein.cloud.network.*; +import org.dasein.cloud.network.AbstractVLANSupport; +import org.dasein.cloud.network.IPVersion; +import org.dasein.cloud.network.InternetGateway; +import org.dasein.cloud.network.VLAN; +import org.dasein.cloud.network.VLANCapabilities; +import org.dasein.cloud.network.VLANState; import org.dasein.cloud.util.APITrace; import org.dasein.cloud.util.Cache; import org.dasein.cloud.util.CacheLevel; @@ -37,7 +41,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; /** * Implements support for vCloud networking. @@ -68,36 +75,6 @@ public VLANCapabilities getCapabilities() throws CloudException, InternalExcepti return capabilities; } - @Nonnull - @Override - public String getProviderTermForNetworkInterface(@Nonnull Locale locale) { - try { - return getCapabilities().getProviderTermForNetworkInterface(locale); - } catch (CloudException | InternalException e) { - throw new RuntimeException(e); - } - } - - @Nonnull - @Override - public String getProviderTermForSubnet(@Nonnull Locale locale) { - try { - return getCapabilities().getProviderTermForSubnet(locale); - } catch (CloudException | InternalException e) { - throw new RuntimeException(e); - } - } - - @Nonnull - @Override - public String getProviderTermForVlan(@Nonnull Locale locale) { - try { - return getCapabilities().getProviderTermForVlan(locale); - } catch (CloudException | InternalException e) { - throw new RuntimeException(e); - } - } - @Override public VLAN getVlan(@Nonnull String vlanId) throws CloudException, InternalException { APITrace.begin(getProvider(), "VLAN.getVlan"); @@ -128,6 +105,11 @@ public VLAN getVlan(@Nonnull String vlanId) throws CloudException, InternalExcep return null; } + @Override + public boolean isNetworkInterfaceSupportEnabled() throws CloudException, InternalException { + return false; + } + @Override public boolean isSubscribed() throws CloudException, InternalException { APITrace.begin(getProvider(), "VLAN.isSubscribed"); diff --git a/src/main/java/org/dasein/cloud/vcloud/vCloudException.java b/src/main/java/org/dasein/cloud/vcloud/vCloudException.java index cdaa8f2..872535b 100644 --- a/src/main/java/org/dasein/cloud/vcloud/vCloudException.java +++ b/src/main/java/org/dasein/cloud/vcloud/vCloudException.java @@ -82,12 +82,27 @@ else if( attr.getNodeName().equalsIgnoreCase("minorErrorCode") && attr.hasChildN } data.title = major + ":" + minor; data.description = message; - if( code == HttpServletResponse.SC_FORBIDDEN || code == HttpServletResponse.SC_UNAUTHORIZED ) { - data.type = CloudErrorType.AUTHENTICATION; - } - else { - data.type = CloudErrorType.GENERAL; + CloudErrorType errorType; + + switch ((code)) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_UNAUTHORIZED: + case HttpServletResponse.SC_FORBIDDEN: + errorType = CloudErrorType.AUTHENTICATION; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case 429: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; } + data.type = errorType; return data; } diff --git a/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java b/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java index 829a8b6..12139ef 100644 --- a/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java +++ b/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java @@ -46,11 +46,15 @@ import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; import org.apache.log4j.Logger; +import org.dasein.cloud.AuthenticationException; import org.dasein.cloud.CloudErrorType; import org.dasein.cloud.CloudException; +import org.dasein.cloud.CommunicationException; import org.dasein.cloud.ContextRequirements; +import org.dasein.cloud.GeneralCloudException; import org.dasein.cloud.InternalException; import org.dasein.cloud.ProviderContext; +import org.dasein.cloud.ResourceNotFoundException; import org.dasein.cloud.Taggable; import org.dasein.cloud.dc.DataCenter; import org.dasein.cloud.dc.Region; @@ -59,8 +63,8 @@ import org.dasein.cloud.util.CacheLevel; import org.dasein.util.CalendarWrapper; import org.dasein.util.uom.time.Day; -import org.dasein.util.uom.time.TimePeriod; import org.dasein.util.uom.time.Minute; +import org.dasein.util.uom.time.TimePeriod; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -106,6 +110,11 @@ public class vCloudMethod { static public final String CREATE_DISK = "createDisk"; static public final String INSTANTIATE_VAPP = "instantiateVApp"; + /** + * 429 Too many requests The user has sent too many requests in a given amount of time + */ + static public final int TOO_MANY_REQUESTS = 429; + static public boolean isSupported(@Nonnull String version) { for( String v : VERSIONS ) { if( version.equals(v) ) { @@ -287,8 +296,11 @@ private void loadOrg(@Nonnull String endpoint, @Nonnull Org org, @Nonnull String logger.debug("HTTP STATUS: " + code); - if( code == HttpServletResponse.SC_NOT_FOUND || code == HttpServletResponse.SC_FORBIDDEN ) { - throw new CloudException("Org URL is invalid"); + if( code == HttpServletResponse.SC_NOT_FOUND ) { + throw new ResourceNotFoundException("Org URL is invalid: "+org.url); + } + else if (code == HttpServletResponse.SC_FORBIDDEN ) { + throw new AuthenticationException("Permissions issue with cloud account for org URL "+org.url).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN); } else if( code == HttpServletResponse.SC_UNAUTHORIZED ) { authenticate(true); @@ -296,7 +308,7 @@ else if( code == HttpServletResponse.SC_UNAUTHORIZED ) { return; } else if( code == HttpServletResponse.SC_NO_CONTENT ) { - throw new CloudException("No content from org URL"); + throw new GeneralCloudException("No content from org URL", CloudErrorType.GENERAL); } else if( code == HttpServletResponse.SC_OK ) { try { @@ -315,7 +327,7 @@ else if( code == HttpServletResponse.SC_OK ) { } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error", e); } } else { @@ -336,10 +348,25 @@ else if( code == HttpServletResponse.SC_OK ) { } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error", e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((code)) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -353,7 +380,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, code, response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, code, response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + code + " : " + data.title + "] " + data.description); throw new vCloudException(data); @@ -366,7 +393,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } if( xml == null ) { - throw new CloudException("No content from org URL"); + throw new GeneralCloudException("No content from org URL", CloudErrorType.GENERAL); } Document doc = parseXML(xml); String docElementTagName = doc.getDocumentElement().getTagName(); @@ -410,16 +437,13 @@ else if( code == HttpServletResponse.SC_OK ) { } } } - throw new CloudException("Could not find " + orgId + " among listed orgs"); + throw new ResourceNotFoundException("Could not find " + orgId + " among listed orgs"); } public @Nonnull Org authenticate(boolean force) throws CloudException, InternalException { Cache cache = Cache.getInstance(provider, "vCloudOrgs", Org.class, CacheLevel.CLOUD_ACCOUNT, new TimePeriod(25, TimePeriod.MINUTE)); ProviderContext ctx = provider.getContext(); - if( ctx == null ) { - throw new CloudException("No context was defined for this request"); - } String accountNumber = ctx.getAccountNumber(); Iterable orgs = cache.get(ctx); Iterator it = ((force || orgs == null) ? null : orgs.iterator()); @@ -495,7 +519,7 @@ else if( code == HttpServletResponse.SC_OK ) { status = response.getStatusLine(); } catch( IOException e ) { - throw new CloudException(e); + throw new CommunicationException("I/O error in authenticate method", e); } if( status.getStatusCode() == HttpServletResponse.SC_OK ) { if( matches(getAPIVersion(), "0.8", "0.8") ) { @@ -523,7 +547,7 @@ else if( code == HttpServletResponse.SC_OK ) { org.token = response.getFirstHeader("x-vcloud-authorization").getValue(); } if( org.token == null ) { - throw new CloudException(CloudErrorType.AUTHENTICATION, 200, "Token Empty", "No token was provided"); + throw new AuthenticationException(CloudErrorType.AUTHENTICATION, 200, "Token Empty", "No token was provided"); } HttpEntity entity = response.getEntity(); String body; @@ -536,7 +560,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } try { ByteArrayInputStream bas = new ByteArrayInputStream(body.getBytes()); @@ -632,13 +656,13 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( ParserConfigurationException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( SAXException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } } else { @@ -655,9 +679,25 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((status.getStatusCode())) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } + if( body != null && !body.equals("") ) { Document doc = parseXML(body); @@ -671,15 +711,15 @@ else if( code == HttpServletResponse.SC_OK ) { } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, status.getStatusCode(), response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, status.getStatusCode(), response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + status.getStatusCode() + " : " + data.title + "] " + data.description); throw new vCloudException(data); } - throw new CloudException(CloudErrorType.AUTHENTICATION, status.getStatusCode(), status.getReasonPhrase(), "Authentication failed"); + throw new AuthenticationException(CloudErrorType.AUTHENTICATION, status.getStatusCode(), status.getReasonPhrase(), "Authentication failed"); } if( org.endpoint == null ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), "No Org", "No org was identified for " + ctx.getAccountNumber()); + throw new GeneralCloudException(CloudErrorType.GENERAL, status.getStatusCode(), "No Org", "No org was identified for " + ctx.getAccountNumber()); } cache.put(ctx, Collections.singletonList(org)); loadVDCs(org); @@ -748,7 +788,7 @@ private void addAuth(HttpRequestBase method, @Nonnull String token) throws Cloud } catch( IOException e ) { logger.error("I/O error from server communications: " + e.getMessage()); - throw new InternalException(e); + throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e); } int code = response.getStatusLine().getStatusCode(); @@ -775,10 +815,29 @@ else if( code != HttpServletResponse.SC_NOT_FOUND && code != HttpServletResponse } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((code)) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_FORBIDDEN: + errorType = CloudErrorType.AUTHENTICATION; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } + if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -792,7 +851,7 @@ else if( code != HttpServletResponse.SC_NOT_FOUND && code != HttpServletResponse } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, code, response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, code, response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + code + " : " + data.title + "] " + data.description); throw new vCloudException(data); @@ -813,7 +872,7 @@ else if( code != HttpServletResponse.SC_NOT_FOUND && code != HttpServletResponse } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } return xml; } @@ -879,7 +938,7 @@ else if( code != HttpServletResponse.SC_NOT_FOUND && code != HttpServletResponse } catch( IOException e ) { logger.error("I/O error from server communications: " + e.getMessage()); - throw new InternalException(e); + throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e); } int code = response.getStatusLine().getStatusCode(); @@ -914,7 +973,7 @@ else if( code == HttpServletResponse.SC_OK ) { } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } return xml; } @@ -935,10 +994,25 @@ else if( code == HttpServletResponse.SC_OK ) { } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((code)) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -952,7 +1026,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, code, response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, code, response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + code + " : " + data.title + "] " + data.description); throw new vCloudException(data); @@ -990,13 +1064,10 @@ else if( code == HttpServletResponse.SC_OK ) { protected @Nonnull HttpClient getClient(boolean forAuthentication) throws CloudException, InternalException { ProviderContext ctx = provider.getContext(); - if( ctx == null ) { - throw new CloudException("No context was defined for this request"); - } String endpoint = ctx.getCloud().getEndpoint(); if( endpoint == null ) { - throw new CloudException("No cloud endpoint was defined"); + throw new InternalException("No cloud endpoint was defined"); } boolean ssl = endpoint.startsWith("https"); int targetPort; @@ -1010,7 +1081,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( URISyntaxException e ) { - throw new CloudException(e); + throw new InternalException(e); } HttpHost targetHost = new HttpHost(uri.getHost(), targetPort, uri.getScheme()); HttpParams params = new BasicHttpParams(); @@ -1230,9 +1301,6 @@ public int getNetworkQuota() throws CloudException, InternalException { ProviderContext ctx = provider.getContext(); - if( ctx == null ) { - throw new CloudException("No context was defined for this request"); - } { Iterable versions = cache.get(ctx); @@ -1285,7 +1353,7 @@ public int getNetworkQuota() throws CloudException, InternalException { status = response.getStatusLine(); } catch( IOException e ) { - throw new CloudException(e); + throw new CommunicationException("I/O Exception getting api version", e); } if( status.getStatusCode() == HttpServletResponse.SC_OK ) { HttpEntity entity = response.getEntity(); @@ -1299,7 +1367,7 @@ public int getNetworkQuota() throws CloudException, InternalException { } } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } try { ByteArrayInputStream bas = new ByteArrayInputStream(body.getBytes()); @@ -1363,7 +1431,7 @@ else if( attr.getNodeName().equalsIgnoreCase("LoginUrl") && attr.hasChildNodes() set.add(v); } if( set.isEmpty() ) { - throw new CloudException("Unable to identify a supported version"); + throw new GeneralCloudException("Unable to identify a supported version", CloudErrorType.GENERAL); } Version v = set.iterator().next(); @@ -1371,13 +1439,13 @@ else if( attr.getNodeName().equalsIgnoreCase("LoginUrl") && attr.hasChildNodes() return v; } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( ParserConfigurationException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( SAXException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } } else { @@ -1398,10 +1466,30 @@ else if( attr.getNodeName().equalsIgnoreCase("LoginUrl") && attr.hasChildNodes() } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((status.getStatusCode())) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_UNAUTHORIZED: + case HttpServletResponse.SC_FORBIDDEN: + errorType = CloudErrorType.AUTHENTICATION; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } + if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -1415,7 +1503,7 @@ else if( attr.getNodeName().equalsIgnoreCase("LoginUrl") && attr.hasChildNodes() } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, status.getStatusCode(), response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, status.getStatusCode(), response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + status.getStatusCode() + " : " + data.title + "] " + data.description); throw new vCloudException(data); @@ -1552,7 +1640,7 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException status = response.getStatusLine(); } catch( IOException e ) { - throw new CloudException(e); + throw new CommunicationException("Error loading vdcs", e); } if( status.getStatusCode() == HttpServletResponse.SC_OK ) { HttpEntity entity = response.getEntity(); @@ -1566,7 +1654,7 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException } } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } try { ByteArrayInputStream bas = new ByteArrayInputStream(body.getBytes()); @@ -1614,13 +1702,13 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException org.setVdcs(vdcs); } catch( IOException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( ParserConfigurationException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( SAXException e ) { - throw new CloudException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } } else { @@ -1640,10 +1728,29 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((status.getStatusCode())) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_UNAUTHORIZED: + case HttpServletResponse.SC_FORBIDDEN: + errorType = CloudErrorType.AUTHENTICATION; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -1657,7 +1764,7 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, status.getStatusCode(), response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, status.getStatusCode(), response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + status.getStatusCode() + " : " + data.title + "] " + data.description); throw new vCloudException(data); @@ -1706,7 +1813,7 @@ else if( attr.getNodeName().equalsIgnoreCase("minorErrorCode") && attr.hasChildN minor = attr.getFirstChild().getNodeValue().trim(); } } - throw new CloudException(type, 200, major + ":" + minor, message); + throw new GeneralCloudException(type, 0, major + ":" + minor, message); } public void parseMetaData(@Nonnull Taggable resource, @Nonnull String xml) throws CloudException, InternalException { @@ -1766,7 +1873,7 @@ else if( part.getNodeName().equalsIgnoreCase(nsString + "Value") && part.hasChil throw new InternalException(e); } catch( SAXException e ) { - throw new CloudException(e); + throw new InternalException(e); } catch( IOException e ) { throw new InternalException(e); @@ -1796,7 +1903,7 @@ else if( vdc == null ) { } } if( vdc == null ) { - throw new CloudException("No VDC was identified for this request (requested " + vdcId + ")"); + throw new ResourceNotFoundException("No VDC was identified for this request (requested " + vdcId + ")"); } String contentType; @@ -1817,10 +1924,10 @@ else if( action.equals(CREATE_DISK) ) { endpoint = vdc.actions.get(contentType); } else { - throw new CloudException("Unknown content type for post"); + throw new GeneralCloudException("Unknown content type for post", CloudErrorType.INVALID_USER_DATA); } if( endpoint == null) { - throw new CloudException("No endpoint for " + action); + throw new GeneralCloudException("No endpoint for " + action, CloudErrorType.GENERAL); } return post(action, endpoint, contentType, payload); } @@ -1888,14 +1995,14 @@ else if( action.equals(CREATE_DISK) ) { } catch( IOException e ) { logger.error("I/O error from server communications: " + e.getMessage()); - throw new InternalException(e); + throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e); } int code = response.getStatusLine().getStatusCode(); logger.debug("HTTP STATUS: " + code); if( code == HttpServletResponse.SC_NOT_FOUND ) { - throw new CloudException("No action match for " + endpoint); + throw new ResourceNotFoundException("No action match for " + endpoint); } else if( code == HttpServletResponse.SC_UNAUTHORIZED ) { authenticate(true); @@ -1920,7 +2027,7 @@ else if( code == HttpServletResponse.SC_OK || code == HttpServletResponse.SC_CRE } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } return xml; } @@ -1941,10 +2048,28 @@ else if( code == HttpServletResponse.SC_OK || code == HttpServletResponse.SC_CRE } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((code)) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_FORBIDDEN: + errorType = CloudErrorType.AUTHENTICATION; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -1958,7 +2083,7 @@ else if( code == HttpServletResponse.SC_OK || code == HttpServletResponse.SC_CRE } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, code, response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, code, response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + code + " : " + data.title + "] " + data.description); throw new vCloudException(data); @@ -2124,14 +2249,14 @@ public void delMetaData(@Nonnull String resource, @Nonnull String id, @Nonnull M } catch( IOException e ) { logger.error("I/O error from server communications: " + e.getMessage()); - throw new InternalException(e); + throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e); } int code = response.getStatusLine().getStatusCode(); logger.debug("HTTP STATUS: " + code); if( code == HttpServletResponse.SC_NOT_FOUND ) { - throw new CloudException("No action match for " + endpoint); + throw new ResourceNotFoundException("No action match for " + endpoint); } else if( code == HttpServletResponse.SC_UNAUTHORIZED ) { authenticate(true); @@ -2156,7 +2281,7 @@ else if( code == HttpServletResponse.SC_OK || code == HttpServletResponse.SC_CRE } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } return xml; } @@ -2177,10 +2302,28 @@ else if( code == HttpServletResponse.SC_OK || code == HttpServletResponse.SC_CRE } catch( IOException e ) { logger.error("Failed to read response error due to a cloud I/O error: " + e.getMessage()); - throw new CloudException(e); + throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e); } vCloudException.Data data = null; + CloudErrorType errorType; + switch ((code)) { + case HttpServletResponse.SC_BAD_REQUEST: + errorType = CloudErrorType.INVALID_USER_DATA; + break; + case HttpServletResponse.SC_FORBIDDEN: + errorType = CloudErrorType.AUTHENTICATION; + break; + case HttpServletResponse.SC_SERVICE_UNAVAILABLE: + errorType = CloudErrorType.COMMUNICATION; + break; + case TOO_MANY_REQUESTS: + errorType = CloudErrorType.THROTTLING; + break; + default: + errorType = CloudErrorType.GENERAL; + break; + } if( xml != null && !xml.equals("") ) { Document doc = parseXML(xml); @@ -2194,7 +2337,7 @@ else if( code == HttpServletResponse.SC_OK || code == HttpServletResponse.SC_CRE } } if( data == null ) { - throw new vCloudException(CloudErrorType.GENERAL, code, response.getStatusLine().getReasonPhrase(), "No further information"); + throw new vCloudException(errorType, code, response.getStatusLine().getReasonPhrase(), "No further information"); } logger.error("[" + code + " : " + data.title + "] " + data.description); throw new vCloudException(data); From 38745fe4ee22b78a95afe619cf101b5c929c6045 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Wed, 6 Jan 2016 16:18:46 +0000 Subject: [PATCH 2/7] public image list fix --- .../cloud/vcloud/compute/TemplateSupport.java | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java index 6199254..36ceceb 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java @@ -68,6 +68,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TimeZone; @@ -508,6 +509,15 @@ private Iterable listPrivateCatalogs() throws CloudException, InternalE Cache cache = Cache.getInstance(getProvider(), "listImages", MachineImage.class, CacheLevel.REGION_ACCOUNT, new TimePeriod(6, TimePeriod.MINUTE)); Iterable imageList = cache.get(getContext()); if (imageList != null) { + if (options != null) { + List tmp = new ArrayList(); + for (MachineImage img : imageList) { + if (options.matches(img)) { + tmp.add(img); + } + } + return tmp; + } return imageList; } @@ -543,6 +553,15 @@ private Iterable listPrivateCatalogs() throws CloudException, InternalE Iterable imageList2 = cache.get(getContext()); if (imageList2 != null) { // A thread we were waiting on has refreshed the cache + if (options != null) { + List tmp = new ArrayList(); + for (MachineImage img : imageList2) { + if (options.matches(img)) { + tmp.add(img); + } + } + return tmp; + } return imageList2; } @@ -588,25 +607,23 @@ private Iterable listPrivateCatalogs() throws CloudException, InternalE String catalogItemId = ((vCloud)getProvider()).toID(href.getNodeValue().trim()); MachineImage image = loadTemplate(catalog.owner, catalogItemId, catalog.published); if( image != null ) { - if( options == null || options.matches(image) ) { - image.setProviderOwnerId(catalog.owner); - try { - String metaData = method.get("vAppTemplate", image.getProviderMachineImageId() + "/metadata"); - if( metaData != null && !metaData.equals("") ) { - method.parseMetaData(image, metaData); - } + image.setProviderOwnerId(catalog.owner); + try { + String metaData = method.get("vAppTemplate", image.getProviderMachineImageId() + "/metadata"); + if( metaData != null && !metaData.equals("") ) { + method.parseMetaData(image, metaData); } - catch( Throwable warning ) { - if (logger.isDebugEnabled()) { - logger.warn("Failed to get and parse image metadata.", warning); - } - else { - logger.warn("Failed to get and parse image metadata."); - } + } + catch( Throwable warning ) { + if (logger.isDebugEnabled()) { + logger.warn("Failed to get and parse image metadata.", warning); + } + else { + logger.warn("Failed to get and parse image metadata."); } - image.setTag("catalogItemId", catalogItemId); - images.add(image); } + image.setTag("catalogItemId", catalogItemId); + images.add(image); } } } @@ -1081,6 +1098,9 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C if( options == null || options.matches(image) ) { image.setProviderOwnerId(catalog.owner); image.setTag("catalogItemId", catalogItemId); + if (image.getTag("public") != null && image.getTag("public").equals("true")) { + image = image.sharedWithPublic(); + } images.add(image); } } From 4107ac287b41e6fc5c49aca6146ec5c1bc11019a Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Thu, 7 Jan 2016 11:32:07 +0000 Subject: [PATCH 3/7] unit tests for image fixes tests for checking public tags and returning filtered list from cache --- pom.xml | 6 ++ .../org/dasein/cloud/vcloud/TemplateTest.java | 98 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/test/java/org/dasein/cloud/vcloud/TemplateTest.java diff --git a/pom.xml b/pom.xml index 78a5ce4..1a53178 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,12 @@ test false + + org.jmockit + jmockit + 1.19 + test + junit junit diff --git a/src/test/java/org/dasein/cloud/vcloud/TemplateTest.java b/src/test/java/org/dasein/cloud/vcloud/TemplateTest.java new file mode 100644 index 0000000..fa0dae7 --- /dev/null +++ b/src/test/java/org/dasein/cloud/vcloud/TemplateTest.java @@ -0,0 +1,98 @@ +package org.dasein.cloud.vcloud; + +import mockit.Mocked; +import mockit.NonStrictExpectations; +import org.dasein.cloud.CloudException; +import org.dasein.cloud.InternalException; +import org.dasein.cloud.ProviderContext; +import org.dasein.cloud.compute.Architecture; +import org.dasein.cloud.compute.ImageClass; +import org.dasein.cloud.compute.ImageFilterOptions; +import org.dasein.cloud.compute.MachineImage; +import org.dasein.cloud.compute.MachineImageState; +import org.dasein.cloud.compute.Platform; +import org.dasein.cloud.util.Cache; +import org.dasein.cloud.util.CacheLevel; +import org.dasein.cloud.vcloud.compute.TemplateSupport; +import org.dasein.util.uom.time.Minute; +import org.dasein.util.uom.time.TimePeriod; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +/** + * User: daniellemayne + * Date: 07/01/2016 + * Time: 08:45 + */ +public class TemplateTest { + @Mocked + ProviderContext providerContextMock; + @Mocked + vCloud vcloudMock; + + private TemplateSupport templateSupport; + private Cache imgCache = null; + + private Iterable getTestTemplateList() { + List list = new ArrayList(); + + MachineImage img = MachineImage.getInstance("OWNER", "REGION_ID", "IMG_1", ImageClass.MACHINE, MachineImageState.ACTIVE, "IMAGE_1", "IMAGE1_DESCRIPTION", Architecture.I64, Platform.CENT_OS); + img = img.sharedWithPublic(); + img.setTag("public", "true"); + list.add(img); + img = MachineImage.getInstance("OWNER", "REGION_ID", "IMG_2", ImageClass.MACHINE, MachineImageState.ACTIVE, "IMAGE_2", "IMAGE2_DESCRIPTION", Architecture.I64, Platform.CENT_OS); + list.add(img); + img = MachineImage.getInstance("OWNER", "REGION_ID", "IMG_3", ImageClass.MACHINE, MachineImageState.ACTIVE, "IMAGE_3", "IMAGE3_DESCRIPTION", Architecture.I64, Platform.CENT_OS); + list.add(img); + img = MachineImage.getInstance("OWNER", "REGION_ID", "IMG_4", ImageClass.MACHINE, MachineImageState.ACTIVE, "IMAGE_4", "IMAGE4_DESCRIPTION", Architecture.I64, Platform.CENT_OS); + list.add(img); + img = MachineImage.getInstance("OWNER", "REGION_ID", "IMG_5", ImageClass.MACHINE, MachineImageState.ACTIVE, "IMAGE_5", "IMAGE5_DESCRIPTION", Architecture.I64, Platform.CENT_OS); + list.add(img); + return list; + } + + @Before + public void setUp() { + templateSupport = new TemplateSupport(vcloudMock); + } + + @Test + public void listPublicTemplates() throws CloudException, InternalException { + new NonStrictExpectations(TemplateSupport.class){ + { + templateSupport.searchPublicImages((ImageFilterOptions) any); + result = getTestTemplateList(); + } + }; + + Iterable images = templateSupport.searchPublicImages(ImageFilterOptions.getInstance()); + for (MachineImage image : images) { + Boolean isPublicTag = (image.getTag("public") != null); + Boolean isPublic = image.isPublic(); + assertEquals("The public tag and isPublic attributes do not match", isPublic, isPublicTag); + } + } + + @Test + public void listTemplatesFilterShouldBeAppliedToCache() throws CloudException, InternalException { + imgCache = Cache.getInstance(vcloudMock, "listImages", MachineImage.class, CacheLevel.REGION_ACCOUNT, new TimePeriod(6, TimePeriod.MINUTE)); + imgCache.put(providerContextMock, getTestTemplateList()); + + new NonStrictExpectations(TemplateSupport.class) { + { + vcloudMock.getContext(); + result = providerContextMock; + } + }; + + imgCache.put(providerContextMock, getTestTemplateList()); + Iterable images = templateSupport.listImages(ImageFilterOptions.getInstance().withImageClass(ImageClass.KERNEL)); + assertFalse("There are no kernel images in test list so returned iterable should be empty", images.iterator().hasNext()); + } +} From 44e46f73dacb0ccaa4a33e20c958e96650a1f493 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Tue, 12 Jan 2016 09:16:21 +0000 Subject: [PATCH 4/7] remove deprecated method replaced by capability --- .../org/dasein/cloud/vcloud/network/HybridVLANSupport.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java b/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java index 2fbdac8..ec9796f 100644 --- a/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/network/HybridVLANSupport.java @@ -105,11 +105,6 @@ public VLAN getVlan(@Nonnull String vlanId) throws CloudException, InternalExcep return null; } - @Override - public boolean isNetworkInterfaceSupportEnabled() throws CloudException, InternalException { - return false; - } - @Override public boolean isSubscribed() throws CloudException, InternalException { APITrace.begin(getProvider(), "VLAN.isSubscribed"); From 1546f8131d3a9d624fcdc7bee82c883dd668cacb Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Wed, 20 Jan 2016 12:08:33 +0000 Subject: [PATCH 5/7] exceptions improvements --- .../org/dasein/cloud/vcloud/vCloudMethod.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java b/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java index 12139ef..9fb6584 100644 --- a/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java +++ b/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java @@ -547,7 +547,7 @@ else if( code == HttpServletResponse.SC_OK ) { org.token = response.getFirstHeader("x-vcloud-authorization").getValue(); } if( org.token == null ) { - throw new AuthenticationException(CloudErrorType.AUTHENTICATION, 200, "Token Empty", "No token was provided"); + throw new AuthenticationException(200, "Token Empty", "No token was provided"); } HttpEntity entity = response.getEntity(); String body; @@ -560,7 +560,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } try { ByteArrayInputStream bas = new ByteArrayInputStream(body.getBytes()); @@ -656,13 +656,13 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( ParserConfigurationException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( SAXException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } } else { @@ -679,7 +679,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } vCloudException.Data data = null; CloudErrorType errorType; @@ -716,7 +716,7 @@ else if( code == HttpServletResponse.SC_OK ) { logger.error("[" + status.getStatusCode() + " : " + data.title + "] " + data.description); throw new vCloudException(data); } - throw new AuthenticationException(CloudErrorType.AUTHENTICATION, status.getStatusCode(), status.getReasonPhrase(), "Authentication failed"); + throw new AuthenticationException(status.getStatusCode(), status.getReasonPhrase(), "Authentication failed"); } if( org.endpoint == null ) { throw new GeneralCloudException(CloudErrorType.GENERAL, status.getStatusCode(), "No Org", "No org was identified for " + ctx.getAccountNumber()); @@ -1367,7 +1367,7 @@ public int getNetworkQuota() throws CloudException, InternalException { } } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } try { ByteArrayInputStream bas = new ByteArrayInputStream(body.getBytes()); @@ -1439,13 +1439,13 @@ else if( attr.getNodeName().equalsIgnoreCase("LoginUrl") && attr.hasChildNodes() return v; } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( ParserConfigurationException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( SAXException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } } else { @@ -1654,7 +1654,7 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException } } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } try { ByteArrayInputStream bas = new ByteArrayInputStream(body.getBytes()); @@ -1702,13 +1702,13 @@ private void loadVDCs(@Nonnull Org org) throws CloudException, InternalException org.setVdcs(vdcs); } catch( IOException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( ParserConfigurationException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } catch( SAXException e ) { - throw new CommunicationException(CloudErrorType.COMMUNICATION, status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); + throw new CommunicationException(status.getStatusCode(), status.getReasonPhrase(), e.getMessage()); } } else { From 391289ffbcd500af27480eb938f6125bd09e963d Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Mon, 25 Jan 2016 10:09:32 +0000 Subject: [PATCH 6/7] upgrade to latest core --- .../cloud/vcloud/compute/DiskSupport.java | 2 +- .../cloud/vcloud/compute/TemplateSupport.java | 20 ++++++++-------- .../cloud/vcloud/compute/vAppSupport.java | 24 +++++++++---------- .../org/dasein/cloud/vcloud/vCloudMethod.java | 10 ++++---- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java index 00df955..0ab6b28 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/DiskSupport.java @@ -182,7 +182,7 @@ public void detach(@Nonnull String volumeId, boolean force) throws InternalExcep Volume volume = getVolume(volumeId); if( volume == null ) { - throw new ResourceNotFoundException("No such volume: " + volumeId); + throw new ResourceNotFoundException("Volume", volumeId); } String serverId = volume.getProviderVirtualMachineId(); diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java index 36ceceb..d98464d 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/TemplateSupport.java @@ -118,16 +118,16 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As String vAppId = (vm == null ? null : (String)vm.getTag(vAppSupport.PARENT_VAPP_ID)); if( vm == null ) { - throw new ResourceNotFoundException("No such virtual machine: " + vmId); + throw new ResourceNotFoundException("Virtual machine", vmId); } else if( vAppId == null ) { - throw new ResourceNotFoundException("Unable to determine virtual machine vApp for capture: " + vmId); + throw new ResourceNotFoundException("Virtual machine vApp for virtual machine", vmId); } long timeout = (System.currentTimeMillis() + CalendarWrapper.MINUTE * 10L); while( timeout > System.currentTimeMillis() ) { if( vm == null ) { - throw new ResourceNotFoundException("VM " + vmId + " went away"); + throw new ResourceNotFoundException("VirtualMachine ", vmId); } if( !vm.getCurrentState().equals(VmState.PENDING) ) { break; @@ -168,7 +168,7 @@ else if( vAppId == null ) { logger.warn("The cloud thinks the vApp or VM is still running; going to check what's going on: " + e.getMessage()); vm = ((vCloud)getProvider()).getComputeServices().getVirtualMachineSupport().getVirtualMachine(vmId); if( vm == null ) { - throw new ResourceNotFoundException("Virtual machine went away"); + throw new ResourceNotFoundException("Virtual machine", vmId); } if( !vm.getCurrentState().equals(VmState.STOPPED) ) { logger.warn("Current state of VM: " + vm.getCurrentState()); @@ -189,7 +189,7 @@ else if( vAppId == null ) { NodeList vapps = doc.getElementsByTagName("VAppTemplate"); if( vapps.getLength() < 1 ) { - throw new ResourceNotFoundException("No vApp templates were found in response"); + throw new ResourceNotFoundException("vApp templates were not found in response", "n/a"); } Node vapp = vapps.item(0); String imageId = null; @@ -199,12 +199,12 @@ else if( vAppId == null ) { imageId = ((vCloud)getProvider()).toID(href.getNodeValue().trim()); } if( imageId == null || imageId.length() < 1 ) { - throw new ResourceNotFoundException("No imageId was found in response"); + throw new ResourceNotFoundException("ImageId not found in response", "n/a"); } MachineImage img = loadVapp(imageId, getContext().getAccountNumber(), false, options.getName(), options.getDescription(), System.currentTimeMillis()); if( img == null ) { - throw new ResourceNotFoundException("Image was lost"); + throw new ResourceNotFoundException("Image", imageId); } method.waitFor(response); publish(img); @@ -263,11 +263,11 @@ private void publish(@Nonnull MachineImage img) throws CloudException, InternalE } } if( href == null ) { - throw new ResourceNotFoundException("No catalog could be identified for publishing vApp template " + img.getProviderMachineImageId()); + throw new ResourceNotFoundException("Catalog for publishing vApp template", img.getProviderMachineImageId()); } c = getCatalog(false, href); if( c == null ) { - throw new ResourceNotFoundException("No catalog could be identified for publishing vApp template " + img.getProviderMachineImageId()); + throw new ResourceNotFoundException("Catalog for publishing vApp template ", img.getProviderMachineImageId()); } } @@ -1033,7 +1033,7 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C MachineImage image = getImage(providerImageId); if( image == null ) { - throw new ResourceNotFoundException("No such image: " + providerImageId); + throw new ResourceNotFoundException("Image", providerImageId); } vCloudMethod method = new vCloudMethod((vCloud)getProvider()); String catalogItemId = (String)image.getTag("catalogItemId"); diff --git a/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java b/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java index 7c7770e..67c9c25 100644 --- a/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java +++ b/src/main/java/org/dasein/cloud/vcloud/compute/vAppSupport.java @@ -317,14 +317,14 @@ public boolean isSubscribed() throws CloudException, InternalException { } } if( vdcId == null ) { - throw new ResourceNotFoundException("Unable to identify a target data center for deploying VM"); + throw new ResourceNotFoundException("Target data center for deploying VM", "n/a"); } final VirtualMachineProduct product = getProduct(withLaunchOptions.getStandardProductId()); final vCloudMethod method = new vCloudMethod(getProvider()); final MachineImage img = getProvider().getComputeServices().getImageSupport().getImage(withLaunchOptions.getMachineImageId()); if( img == null ) { - throw new ResourceNotFoundException("No such image: " + withLaunchOptions.getMachineImageId()); + throw new ResourceNotFoundException("Image", withLaunchOptions.getMachineImageId()); } StringBuilder xml = new StringBuilder(); @@ -347,7 +347,7 @@ public boolean isSubscribed() throws CloudException, InternalException { } } if (vlanId == null) { - throw new ResourceNotFoundException("Could not locate default vlan '" + defaultVlanName + "'"); + throw new ResourceNotFoundException("Default vlan", defaultVlanName); } } else if (defaultVlanNameDHCP != null && !defaultVlanNameDHCP.trim().isEmpty()) { throw new GeneralCloudException("No vlan selected and the default is DHCP-based which is not supported", CloudErrorType.GENERAL); @@ -395,7 +395,7 @@ public boolean isSubscribed() throws CloudException, InternalException { } } if (parentId == null || parentHref == null) { - throw new ResourceNotFoundException("Unable to find the network config settings - cannot specify network for this vApp"); + throw new ResourceNotFoundException("Network config settings for image", img.getProviderMachineImageId()); } } @@ -434,7 +434,7 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString xml.append(""); } else { - throw new ResourceNotFoundException("Failed to find vlan " + vlanId); + throw new ResourceNotFoundException("Vlan", vlanId); } xml.append("true"); xml.append(""); @@ -485,7 +485,7 @@ else if (img.getTag("fullNetConf") != null && img.getTag("fullNetConf").toString } catch( Throwable t ) { logger.error("Problem backing out after vApp went away: " + t.getMessage()); } - throw new ResourceNotFoundException("vApp went away: "+vappId); + throw new ResourceNotFoundException("vApp", vappId); } final Document doc = method.parseXML(vAppResponse); @@ -554,7 +554,7 @@ else if (fullname.length() > 128) { } catch( Throwable t ) { logger.error("Problem backing out after failing to identify VM in response: " + t.getMessage()); } - throw new ResourceNotFoundException("Unable to identify VM " + vmId + "."); + throw new ResourceNotFoundException("VM", vmId); } final String fvmId = vmId; @@ -1339,7 +1339,7 @@ private void stopVappOrVm(@Nonnull String id, boolean force) throws CloudExcepti vCloudMethod method = new vCloudMethod(getProvider()); String xml = method.get("vApp", id); if (xml == null) { - throw new ResourceNotFoundException("No information returned for ID: " + id); + throw new ResourceNotFoundException("Vm", id); } Document doc = method.parseXML(xml); String docElementTagName = doc.getDocumentElement().getTagName(); @@ -1361,7 +1361,7 @@ private void stopVappOrVm(@Nonnull String id, boolean force) throws CloudExcepti // 2. It's a VM. Find vApp ID String vAppId = parseParentVappId(nodes, method); if (vAppId == null) { - throw new ResourceNotFoundException("No parent vApp ID found for: " + id); + throw new ResourceNotFoundException("Parent vApp ID found for vm", id); } // 3. Does the vApp contain multiple VMs? @@ -1376,7 +1376,7 @@ private void stopVappOrOneVm(String vAppId, String vmId, boolean force) throws C vCloudMethod method = new vCloudMethod(getProvider()); String xml = method.get("vApp", vAppId); if (xml == null) { - throw new ResourceNotFoundException("No information returned for ID: " + vAppId); + throw new ResourceNotFoundException("Information for vapp", vAppId); } Document doc = method.parseXML(xml); @@ -1417,7 +1417,7 @@ private void stopVappOrOneVm(String vAppId, String vmId, boolean force) throws C // 4b. If the vApp contains just one VM, undeploy the vApp undeploy(vAppId, powerAction); } else { - throw new ResourceNotFoundException("Expected at least one VM"); + throw new ResourceNotFoundException("VM for vapp", vAppId); } } @@ -1576,7 +1576,7 @@ public void terminate(@Nonnull String vmId) throws InternalException, CloudExcep VirtualMachine vm = getVirtualMachine(vmId); if( vm == null ) { - throw new ResourceNotFoundException("No such virtual machine: " + vmId); + throw new ResourceNotFoundException("Virtual machine", vmId); } String vappId = (String)vm.getTag(PARENT_VAPP_ID); Jiterator vms = new Jiterator(); diff --git a/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java b/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java index 9fb6584..d01681d 100644 --- a/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java +++ b/src/main/java/org/dasein/cloud/vcloud/vCloudMethod.java @@ -297,7 +297,7 @@ private void loadOrg(@Nonnull String endpoint, @Nonnull Org org, @Nonnull String logger.debug("HTTP STATUS: " + code); if( code == HttpServletResponse.SC_NOT_FOUND ) { - throw new ResourceNotFoundException("Org URL is invalid: "+org.url); + throw new ResourceNotFoundException("Org URL", org.url); } else if (code == HttpServletResponse.SC_FORBIDDEN ) { throw new AuthenticationException("Permissions issue with cloud account for org URL "+org.url).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN); @@ -437,7 +437,7 @@ else if( code == HttpServletResponse.SC_OK ) { } } } - throw new ResourceNotFoundException("Could not find " + orgId + " among listed orgs"); + throw new ResourceNotFoundException("Org", orgId); } public @Nonnull Org authenticate(boolean force) throws CloudException, InternalException { @@ -1903,7 +1903,7 @@ else if( vdc == null ) { } } if( vdc == null ) { - throw new ResourceNotFoundException("No VDC was identified for this request (requested " + vdcId + ")"); + throw new ResourceNotFoundException("VDC", vdcId); } String contentType; @@ -2002,7 +2002,7 @@ else if( action.equals(CREATE_DISK) ) { logger.debug("HTTP STATUS: " + code); if( code == HttpServletResponse.SC_NOT_FOUND ) { - throw new ResourceNotFoundException("No action match for " + endpoint); + throw new ResourceNotFoundException("Action match("+action+")", endpoint); } else if( code == HttpServletResponse.SC_UNAUTHORIZED ) { authenticate(true); @@ -2256,7 +2256,7 @@ public void delMetaData(@Nonnull String resource, @Nonnull String id, @Nonnull M logger.debug("HTTP STATUS: " + code); if( code == HttpServletResponse.SC_NOT_FOUND ) { - throw new ResourceNotFoundException("No action match for " + endpoint); + throw new ResourceNotFoundException("Action match("+action+")", endpoint); } else if( code == HttpServletResponse.SC_UNAUTHORIZED ) { authenticate(true); From 56406ef4f04d84eec1c4165f3707ba82ce1f0ac5 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Wed, 3 Feb 2016 08:23:52 +0000 Subject: [PATCH 7/7] version update --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1a53178..fa041dc 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ org.dasein dasein-cloud-core - 1.0.1-SNAPSHOT + 0.9.0 compile false