Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return better error messages #64

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/main/java/org/dasein/cloud/vsphere/Vsphere.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,33 @@

package org.dasein.cloud.vsphere;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

import com.vmware.vim25.*;
import com.vmware.vim25.InvalidLoginFaultMsg;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.NoPermission;
import com.vmware.vim25.RuntimeFaultFaultMsg;
import com.vmware.vim25.ServiceContent;
import com.vmware.vim25.UserSession;
import com.vmware.vim25.VimPortType;
import com.vmware.vim25.VimService;
import org.apache.log4j.Logger;
import org.dasein.cloud.*;
import org.dasein.cloud.AbstractCloud;
import org.dasein.cloud.AuthenticationException;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.ContextRequirements;
import org.dasein.cloud.GeneralCloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.vsphere.compute.VsphereCompute;

import org.dasein.cloud.vsphere.network.VSphereNetworkServices;
import org.dasein.util.CalendarWrapper;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.ws.BindingProvider;
import javax.net.ssl.SSLContext;
import javax.xml.ws.BindingProvider;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;


/**
Expand Down Expand Up @@ -143,9 +154,9 @@ public VSphereNetworkServices getNetworkServices() {
if (e.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when retrieving service content", e).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error retrieving service content", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error retrieving service content", e);
} catch (Exception e) {
throw new GeneralCloudException("Error getting service content", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error getting service content", e);
}

List<ContextRequirements.Field> fields = getContextRequirements().getConfigurableValues();
Expand All @@ -171,9 +182,9 @@ public VSphereNetworkServices getNetworkServices() {
if (e.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when logging in", e).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error logging in", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error logging in", e);
} catch (Exception e) {
throw new GeneralCloudException("Error logging in", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error logging in", e);
}

String apiVersion = serviceContent.getAbout().getApiVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public RetrieveResult retrieveObjectList(@Nonnull Vsphere provider, @Nonnull Str
if (e.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when retrieving service content", e).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error retrieving service content for inventory search", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error retrieving service content for inventory search", e);
}

RetrieveResult props;
Expand All @@ -88,9 +88,9 @@ public RetrieveResult retrieveObjectList(@Nonnull Vsphere provider, @Nonnull Str
if (e.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when searching inventory", e).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error retrieving object list", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error retrieving object list", e);
} catch ( Exception e ) {
throw new GeneralCloudException("Error retrieving object list", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error retrieving object list", e);
}

return props;
Expand All @@ -105,9 +105,9 @@ public ManagedObjectReference searchDatastores(Vsphere provider, @Nonnull Manage
if (runtimeFaultFaultMsg.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when searching datastores", runtimeFaultFaultMsg).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error searching datastores", runtimeFaultFaultMsg, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error searching datastores", runtimeFaultFaultMsg);
}catch (Exception e) {
throw new GeneralCloudException("Error searching datastores", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error searching datastores", e);
}
}
}
47 changes: 36 additions & 11 deletions src/main/java/org/dasein/cloud/vsphere/VsphereMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,36 @@

package org.dasein.cloud.vsphere;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nonnull;

import com.vmware.vim25.*;

import org.dasein.cloud.*;
import com.vmware.vim25.InvalidCollectorVersionFaultMsg;
import com.vmware.vim25.InvalidPropertyFaultMsg;
import com.vmware.vim25.LocalizedMethodFault;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.NoPermission;
import com.vmware.vim25.ObjectSpec;
import com.vmware.vim25.ObjectUpdate;
import com.vmware.vim25.ObjectUpdateKind;
import com.vmware.vim25.PropertyChange;
import com.vmware.vim25.PropertyFilterSpec;
import com.vmware.vim25.PropertyFilterUpdate;
import com.vmware.vim25.PropertySpec;
import com.vmware.vim25.RuntimeFaultFaultMsg;
import com.vmware.vim25.ServiceContent;
import com.vmware.vim25.TaskInfoState;
import com.vmware.vim25.UpdateSet;
import com.vmware.vim25.VimPortType;
import com.vmware.vim25.WaitOptions;
import org.dasein.cloud.AuthenticationException;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.GeneralCloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.util.APITrace;
import org.dasein.util.uom.time.Second;
import org.dasein.util.uom.time.TimePeriod;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;

public class VsphereMethod {

private Vsphere provider;
Expand Down Expand Up @@ -113,24 +131,31 @@ public boolean getOperationCurrentStatus(ManagedObjectReference taskmor) throws
}
}
}
if (taskState.getVal().equals(TaskInfoState.ERROR)) {
String detailedMessage = taskError.getVal().toString();
if (taskError.getVal() instanceof LocalizedMethodFault) {
detailedMessage = (((LocalizedMethodFault) taskError.getVal()).getLocalizedMessage());
}
throw new GeneralCloudException("Error waiting on task completion: "+detailedMessage);
}
return (null != taskState) && (taskState.getVal().equals(TaskInfoState.SUCCESS));
} catch (InvalidPropertyFaultMsg e) {
throw new InternalException(e);
} catch (RuntimeFaultFaultMsg e) {
if (e.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when retrieving task status", e).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error getting task progress", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error getting task progress", e);
}catch (InvalidCollectorVersionFaultMsg e) {
throw new GeneralCloudException("Error getting task progress", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error getting task progress", e);
} finally {
try {
vimPort.destroyPropertyFilter(filterSpecRef);
} catch ( RuntimeFaultFaultMsg e ) {
if ( e.getFaultInfo() instanceof NoPermission ) {
throw new AuthenticationException("NoPermission fault when destroying property filter", e).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error destroying property filter", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error destroying property filter", e);
}
APITrace.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.dasein.util.uom.storage.Storage;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -51,12 +50,12 @@ public HardDiskCapabilities(@Nonnull Vsphere provider) {

@Override
public boolean canAttach(VmState vmState) throws InternalException, CloudException {
return (vmState.equals(VmState.RUNNING));
return true;
}

@Override
public boolean canDetach(VmState vmState) throws InternalException, CloudException {
return (vmState.equals(VmState.RUNNING));
return true;
}

@Override
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/dasein/cloud/vsphere/compute/HardDisk.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void attach(@Nonnull String volumeId, @Nonnull String toServer, @Nonnull
TimePeriod interval = new TimePeriod<Second>(30, TimePeriod.SECOND);

if( taskmor != null && !method.getOperationComplete(taskmor, interval, 10) ) {
lastError = new GeneralCloudException("Failed to attach volume: " + method.getTaskError().getVal(), CloudErrorType.GENERAL);
lastError = new GeneralCloudException("Failed to attach volume: " + method.getTaskError().getVal());
}
if( lastError != null ) {
throw lastError;
Expand Down Expand Up @@ -338,12 +338,12 @@ else if (device instanceof VirtualDisk) {
lastError = new ResourceNotFoundException("new volume", "n/a");
}
else {
lastError = new GeneralCloudException("Failed to create volume: " + method.getTaskError().getVal(), CloudErrorType.GENERAL);
lastError = new GeneralCloudException("Failed to create volume: " + method.getTaskError().getVal());
}
if( lastError != null ) {
throw lastError;
}
throw new GeneralCloudException("No volume and no error", CloudErrorType.GENERAL);
throw new GeneralCloudException("No volume and no error");
}
finally {
APITrace.end();
Expand Down Expand Up @@ -426,7 +426,7 @@ public void detach(@Nonnull String volumeId, boolean force) throws InternalExcep
TimePeriod interval = new TimePeriod<Second>(30, TimePeriod.SECOND);

if( !method.getOperationComplete(taskmor, interval, 10) ) {
lastError = new GeneralCloudException("Failed to update VM: " + method.getTaskError().getVal(), CloudErrorType.GENERAL);
lastError = new GeneralCloudException("Failed to update VM: " + method.getTaskError().getVal());
}
if( lastError != null ) {
throw lastError;
Expand Down Expand Up @@ -661,14 +661,14 @@ public void remove(@Nonnull String volumeId) throws InternalException, CloudExce
return;
}
}
throw new GeneralCloudException("Error removing datastore file: " + method.getTaskError().getVal().toString(), CloudErrorType.GENERAL);
throw new GeneralCloudException("Error removing datastore file: " + method.getTaskError().getVal().toString());
} catch ( RuntimeFaultFaultMsg runtimeFaultFaultMsg ) {
if (runtimeFaultFaultMsg.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when removing datastore file", runtimeFaultFaultMsg).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error while removing datastore file", runtimeFaultFaultMsg, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error while removing datastore file", runtimeFaultFaultMsg);
} catch (Exception e) {
throw new GeneralCloudException("Error while removing datastore file", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error while removing datastore file", e);
}
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.log4j.Logger;
import org.dasein.cloud.AsynchronousTask;
import org.dasein.cloud.AuthenticationException;
import org.dasein.cloud.CloudErrorType;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.GeneralCloudException;
import org.dasein.cloud.InternalException;
Expand Down Expand Up @@ -230,7 +229,7 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As
img = getImage(newVmRef.getValue());
}
else {
throw new GeneralCloudException("Failed to capture image: " + method.getTaskError().getVal(), CloudErrorType.GENERAL);
throw new GeneralCloudException("Failed to capture image: " + method.getTaskError().getVal());
}

if( task != null ) {
Expand Down Expand Up @@ -270,9 +269,9 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C
if (runtimeFaultFaultMsg.getFaultInfo() instanceof NoPermission) {
throw new AuthenticationException("NoPermission fault when deleting image", runtimeFaultFaultMsg).withFaultType(AuthenticationException.AuthenticationFaultType.FORBIDDEN);
}
throw new GeneralCloudException("Error when deleting image", runtimeFaultFaultMsg, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error when deleting image", runtimeFaultFaultMsg);
} catch (Exception e) {
throw new GeneralCloudException("Error when deleting image", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Error when deleting image", e);
}
finally {
APITrace.end();
Expand Down
Loading