Package com.cloud.bridge.service.exception

Examples of com.cloud.bridge.service.exception.EC2ServiceException


                if (operation.equalsIgnoreCase("create"))
                    resp = getApi().createTags(cloudStackResourceType, resourceIdList, resourceTagList);
                else if(operation.equalsIgnoreCase("delete"))
                    resp = getApi().deleteTags(cloudStackResourceType, resourceIdList, resourceTagList);
                else
                    throw new EC2ServiceException( ServerError.InternalError, "Unknown operation." );
                if (resp.getSuccess() == false)
                    return false;
            }
            return true;
        } catch (Exception e){
View Full Code Here


        String[] name = request.getParameterValues( "GroupName" );
        if ( null != name && 0 < name.length )
            groupName = name[0];
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - GroupName");
        }

        // -> execute the request
        DeleteSecurityGroupResponse EC2response = EC2SoapServiceImpl.toDeleteSecurityGroupResponse( ServiceProvider.getInstance().getEC2Engine().deleteSecurityGroup( groupName ));
        serializeResponse(response, EC2response);
View Full Code Here

            // for EC2 security groups either a group ID or a group name is accepted
            String[] sgIdList = request.getSecurityGroupIdSet();
            String[] sgNameList = request.getSecurityGroupNameSet();
            if (sgIdList.length != 0 && sgNameList.length != 0)
                throw new EC2ServiceException(ClientError.InvalidParameterCombination,
                        " for EC2 groups either a group ID or a group name is accepted");

            if (sgIdList.length != 0)
                groupIds = constructList(sgIdList);
            if (sgNameList.length != 0)
View Full Code Here

        String[] snapSet = request.getParameterValues( "SnapshotId" );
        if ( null != snapSet && 0 < snapSet.length )
            snapshotId = snapSet[0];
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - SnapshotId");
        }

        // -> execute the request
        DeleteSnapshotResponse EC2response = EC2SoapServiceImpl.toDeleteSnapshotResponse( ServiceProvider.getInstance().getEC2Engine().deleteSnapshot( snapshotId ));
        serializeResponse(response, EC2response);
View Full Code Here

        String[] volSet = request.getParameterValues( "VolumeId" );
        if ( null != volSet && 0 < volSet.length )
            volumeId = volSet[0];
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - VolumeId");
        }

        // -> execute the request
        EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
        CreateSnapshotResponse EC2response = EC2SoapServiceImpl.toCreateSnapshotResponse( engine.createSnapshot( volumeId ), engine);
View Full Code Here

        String errorMessage = error[0];
        if (error.length == 2) { // error code has been supplied
            int errorCode = Integer.parseInt(error[1]);
            if (errorCode == 431) {
                if ( errorMessage.contains("Object vm_instance(uuid:") && errorMessage.contains(") does not exist") ) {
                    throw new EC2ServiceException( ClientError.InvalidInstanceID_NotFound,
                            "Specified Instance ID does not exist");
                } else if ( errorMessage.contains("Unable to find security group by name") ||
                        errorMessage.contains("Unable to find security group") ||
                        ( errorMessage.contains("Object security_group(uuid:") && errorMessage.contains(") does not exist") ) ||
                        errorMessage.contains("Unable to find group by name ") ) {
                    throw new EC2ServiceException( ClientError.InvalidGroup_NotFound,
                            "Specified Security Group does not exist");
                } else if ( errorMessage.contains("Invalid port numbers") ) {
                    throw new EC2ServiceException( ClientError.InvalidPermission_Malformed,
                            "Specified Port value is invalid");
                } else if (errorMessage.contains("Nonexistent account") && errorMessage.contains("when trying to authorize security group rule for security group") ) {
                        throw new EC2ServiceException( ClientError.InvalidPermission_Malformed,
                                "Specified account doesn't exist");
                } else if ( errorMessage.contains("Nonexistent group") && errorMessage.contains("unable to authorize security group rule") ) {
                    throw new EC2ServiceException( ClientError.InvalidPermission_Malformed,
                            "Specified source security group doesn't exist");
                } else if ( errorMessage.contains("Invalid protocol") ) {
                    throw new EC2ServiceException( ClientError.InvalidPermission_Malformed,
                            "Specified protocol is invalid");
                } else if ( errorMessage.contains("is an Invalid CIDR") ) {
                    throw new EC2ServiceException( ClientError.InvalidPermission_Malformed,
                            "Specified CIDR is invalid");
                 }else if ( errorMessage.contains("Nonexistent account") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Specified Account name is invalid");
                } else if ( errorMessage.contains("Object volumes(uuid:") && errorMessage.contains(") does not exist") ) {
                    throw new EC2ServiceException( ClientError.InvalidVolume_NotFound,
                            "Specified Volume ID doesn't exist");
                } else if ( errorMessage.contains("Object snapshots(uuid:") && errorMessage.contains(") does not exist") ) {
                    throw new EC2ServiceException( ClientError.InvalidSnapshot_NotFound,
                            "Specified Snapshot ID doesn't exist");
                } else if ( (errorMessage.contains("A key pair with name '") && errorMessage.contains("' does not exist")) ||
                            (errorMessage.contains("A key pair with name '") && errorMessage.contains("' was not found")) ) {
                    throw new EC2ServiceException( ClientError.InvalidKeyPair_NotFound,
                            "Specified Key pair name is invalid");
                } else if ( errorMessage.contains("A key pair with name '") && errorMessage.contains("' already exists") ) {
                    throw new EC2ServiceException( ClientError.InvalidKeyPair_Duplicate,
                            "Specified Key pair already exists");
                } else if ( errorMessage.contains("Unknown zoneName value") ) {
                    throw new EC2ServiceException( ClientError.InvalidZone_NotFound,
                            "Specified AvailabilityZone name is invalid");
                } else if ( errorMessage.contains("specify a volume that is not attached to any VM") ) {
                    throw new EC2ServiceException( ClientError.DependencyViolation,
                            "Specified Volume is attached to a VM");
                } else if ( errorMessage.contains("Object vm_template(uuid: ")&& errorMessage.contains(") does not exist") ) {
                    throw new EC2ServiceException( ClientError.InvalidAMIID_NotFound,
                            "Specified Image ID does not exist");
                } else if ( errorMessage.contains("unable to find template by id") ) {
                    throw new EC2ServiceException( ClientError.InvalidAMIID_NotFound,
                            "Specified Image ID does not exist");
                } else if ( errorMessage.contains("a group with name") && errorMessage.contains("already exists") ) {
                    throw new EC2ServiceException( ClientError.InvalidGroup_Duplicate,
                            "Specified Security Group already exists");
                } else if ( errorMessage.contains("specified volume is not attached to a VM") ) {
                    throw new EC2ServiceException( ClientError.IncorrectState,
                            "Specified volume is not in the correct state 'attached' for detachment");
                } else if ( errorMessage.contains("Snapshot with specified snapshotId is not in BackedUp state yet and can't be used for volume creation") ) {
                    throw new EC2ServiceException( ClientError.IncorrectState,
                            "Specified snapshot is not in the correct state 'completed' for volume creation");
                } else if ( errorMessage.contains("Can't delete snapshotshot 4 due to it is not in BackedUp Status") ) {
                    throw new EC2ServiceException( ClientError.IncorrectState,
                            "Specified snapshot is not in the correct state 'completed' for deletion");
                } else if ( errorMessage.contains("Public key is invalid") ) {
                    throw new EC2ServiceException( ClientError.InvalidKeyPair_Format,
                            "Format of the specified key is invalid");
                } else if ( errorMessage.contains("Invalid resource type") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Specified resourceId is invalid");
                } else if ( errorMessage.contains("Unable to find tags by parameters specified") ) {
                       throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Specified resourceTag for the specified resourceId doesn't exist");
                } else if ( errorMessage.contains("Failed to enable static nat for the ip address with specified ipId " +
                        "as vm with specified vmId is already associated with specified currentIp") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Specified publicIp is already associated to the specified VM");
                } else if ( errorMessage.contains("Specified IP address id is not associated with any vm Id") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Specified publicIp is not associated to any VM");
                } else if ( errorMessage.contains("specify a VM that is either running or stopped") ) {
                    throw new EC2ServiceException( ClientError.IncorrectInstanceState,
                            "Unable to attach. Specified instances is in an incorrect state");
                } else if ( errorMessage.contains("specify a valid data volume") ) {
                    throw new EC2ServiceException( ClientError.InvalidVolume_NotFound,
                            "Specified volume doen't exist");
                } else if ( errorMessage.contains("VolumeId is not in Ready state, but  in state Allocated. Cannot take snapshot") ) {
                    throw new EC2ServiceException( ClientError.IncorrectState,
                            "Cannot take snapshot. Specified volume is not in the correct state");
                } else if ( errorMessage.contains("Can't delete snapshot") && errorMessage.contains("it is not in BackedUp Status") ) {
                    throw new EC2ServiceException( ClientError.IncorrectState,
                            "Cannot delete snapshot. Specified snapshot is not in the correct state");
                } else if ( errorMessage.contains("Invalid port range") ) {
                    throw new EC2ServiceException( ClientError.InvalidPermission_Malformed,
                            "The specified port range is invalid");
                } else if ( errorMessage.contains("specify a valid User VM") ) {
                    throw new EC2ServiceException( ClientError.InvalidInstanceID_NotFound,
                            "Specified instance is invalid");
                } else if ( errorMessage.contains("No password for VM with specified id found") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "No password for VM with the specified id found");
                } else if ( errorMessage.contains("make sure the virtual machine is stopped and not in an error state before upgrading") ) {
                    throw new EC2ServiceException( ClientError.IncorrectInstanceState,
                            "Unable to modify. Specified instances is not in the correct state 'Stopped'");
                } else if ( errorMessage.contains("Not upgrading vm") && errorMessage.contains("it already has the" +
                        " requested service offering") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Unable to modify. Specified instance already has the requested instanceType");
                }
                // Can't enable static, ip address with specified id is a sourceNat ip address ?
                else {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "The value supplied for a parameter is invalid");
                }
            }
            else if (errorCode == 536) {
                if ( errorMessage.contains("Cannot delete group when it's in use by virtual machines") ) {
                       throw new EC2ServiceException( ClientError.InvalidGroup_InUse,
                            "Group is in use by a virtual machine");
                } else {
                       throw new EC2ServiceException( ClientError.DependencyViolation,
                            "Specified resource is in use");
                }
            }
            else if (errorCode == 531) {
                if ( errorMessage.contains("Acct") && errorMessage.contains("does not have permission to launch" +
                        " instances from Tmpl") ) {
                    throw new EC2ServiceException( ClientError.AuthFailure,
                            "User not authorized to operate on the specified AMI");
                } else {
                    throw new EC2ServiceException( ClientError.AuthFailure, "User not authorized");
                }
            }
            else if (errorCode == 530) {
               if ( errorMessage.contains("deviceId") && errorMessage.contains("is used by VM") ) {
                    throw new EC2ServiceException( ClientError.InvalidDevice_InUse,
                            "Specified Device is already being used by the VM");
                } else if (errorMessage.contains("Entity already exists") ){
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "Specified resource tag already exists");
                } else if ( errorMessage.contains("Template") && errorMessage.contains("has not been completely downloaded") ){
                    throw new EC2ServiceException( ClientError.InvalidAMIID_NotFound,
                            "Specified ImageId is unavailable");
                } else if ( errorMessage.contains("cannot stop VM") && errorMessage.contains("when it is in state Starting") ){
                    throw new EC2ServiceException( ClientError.IncorrectInstanceState,
                            "Unable to stop. One or more of the specified instances is in an incorrect state 'pending'");
                } else if ( errorMessage.contains("Failed to authorize security group ingress rule(s)") ) {
                    throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified Ip-permission is invalid" +
                            " or the Ip-permission already exists");
                } else if ( errorMessage.contains("Failed to reboot vm instance") ) {
                    throw new EC2ServiceException(ClientError.IncorrectInstanceState,
                            "Unable to reboot. One or more of the specified instances is in an incorrect state");
                } else if ( errorMessage.contains("specify a template that is not currently being downloaded") ) {
                    throw new EC2ServiceException(ClientError.IncorrectState,
                            "Unable to deregister. Image is not in the correct state 'available'");
                } else {
                    throw new EC2ServiceException( ServerError.InternalError, "An unexpected error occured");
                }
            }
            else if (errorCode == 534) {
                if ( errorMessage.contains("Maximum number of resources of type 'volume' for account")
                        && errorMessage.contains("has been exceeded") ) {
                    throw new EC2ServiceException( ClientError.VolumeLimitExceeded,
                            "You have reached the limit on the number of volumes that can be created");
                } else if ( errorMessage.contains("Maximum number of resources of type 'public_ip' for account")
                        && errorMessage.contains("has been exceeded") ) {
                    throw new EC2ServiceException( ClientError.AddressLimitExceeded,
                            "You have reached the limit on the number of elastic ip addresses your account can have");
                } else if ( errorMessage.contains("Unable to apply save userdata entry on router") ) {
                    throw new EC2ServiceException( ClientError.InvalidParameterValue,
                            "The value supplied for parameter UserData is invalid");
                } else {
                    throw new EC2ServiceException( ServerError.InternalError, "An unexpected error occured");
                }
            }
            else if (errorCode == 533) {
                if ( errorMessage.contains("Unable to create a deployment for VM") ) {
                    throw new EC2ServiceException( ClientError.InsufficientInstanceCapacity,
                            "There is insufficient capacity available to deploy a VM");
                } else if ( errorMessage.contains("Insufficient address capacity") ) {
                    throw new EC2ServiceException( ServerError.InsufficientAddressCapacity,
                            "Not enough available addresses to satisfy your minimum request");
                } else {
                    throw new EC2ServiceException( ServerError.InternalError, "There is insufficient capacity");
                }
            } else if (errorCode == 401) {
                if ( errorMessage.contains("Unauthorized") ) {
                    throw new EC2ServiceException(ClientError.AuthFailure, "User not authorised");
                } else {
                    throw new EC2ServiceException(ClientError.AuthFailure, "User not authorised");
                }
            } else {
               throw new EC2ServiceException( ServerError.InternalError, "An unexpected error occured");
            }
        } else {
            if ( errorMessage.contains("Unknown zoneName value") ) {
                throw new EC2ServiceException( ClientError.InvalidZone_NotFound,
                        "AvailabilityZone name is invalid");
            } else if ( errorMessage.contains("No ServiceOffering found to be defined by name") ) {
                throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified InstanceType is invalid");
            } else if ( errorMessage.contains("Specified Ip permission is invalid") ) {
                throw new EC2ServiceException(ClientError.InvalidPermission_Malformed, "Specified Ip permission is invalid");
            } else if ( errorMessage.contains("One or more instanceIds do not exist, other instances rebooted") ) {
                throw new EC2ServiceException(ClientError.InvalidInstanceID_NotFound,
                        "One or more InstanceId doesn't exist, other instances rebooted");
            } else if ( errorMessage.contains("Device is not supported") ) {
                throw new EC2ServiceException(ClientError.InvalidParameterValue,
                        "Value specified for parameter Device is invalid");
            } else if ( errorMessage.contains("Volume is not attached to the Instance") ) {
                throw new EC2ServiceException(ClientError.InvalidAttachment_NotFound,
                        "Specified Volume is not attached to the specified Instance");
            } else if ( errorMessage.contains("Volume is not attached to the Device") ) {
                throw new EC2ServiceException(ClientError.InvalidAttachment_NotFound,
                        "Specified Volume is not attached to the specified device");
            } else if ( errorMessage.contains("Unable to create snapshot") ) {
                throw new EC2ServiceException(ServerError.InternalError,
                        "Unable to create snapshot");
            } else if ( errorMessage.contains("Instance must be in stopped state") ) {
                throw new EC2ServiceException(ClientError.IncorrectInstanceState,
                        "Specified instance is not in the correct state 'stopped'");
            } else if ( errorMessage.contains("Image couldn't be created") ) {
                throw new EC2ServiceException(ServerError.InternalError,
                        "Unable to create image");
            } else if ( errorMessage.contains("Failed to start the stopped instance") ) {
                throw new EC2ServiceException(ServerError.InternalError,
                        "Unable to start the instance that was stopped during image creation");
            } else if ( errorMessage.contains("One or more of instanceIds specified is in stopped state") ) {
                throw new EC2ServiceException(ClientError.IncorrectInstanceState,
                        "Unable to reboot. One or more of the specified instances is in an incorrect state 'stopped'");
            } else if ( errorMessage.contains("Specified ipAddress doesn't exist") ) {
                throw new EC2ServiceException(ClientError.InvalidParameterValue, "Specified publicIp doesn't exist");
            } else if ( errorMessage.contains("Min Count is greater than the number of instances left to allocate") ) {
                throw new EC2ServiceException(ClientError.InstanceLimitExceeded,
                        "Specified MinCount parameter is greater than the number of instances you can create");
            } else if ( errorMessage.contains("instanceType not found") ) {
                throw new EC2ServiceException(ClientError.InvalidParameterValue,
                        "Specified instanceType not found");
            } else if ( errorMessage.contains("zone not found") ) {
                throw new EC2ServiceException(ClientError.InvalidZone_NotFound,
                        "Specified zone doesn't exist");
            } else if ( errorMessage.contains("Both groupId and groupName has been specified") ) {
                throw new EC2ServiceException(ClientError.InvalidParameterCombination,
                        " for EC2 groups either a group ID or a group name is accepted");
            } else if ( errorMessage.contains("Insufficient Instance Capacity") ) {
                throw new EC2ServiceException(ServerError.InsufficientInstanceCapacity, "Insufficient Instance Capacity" );
            } else if ( errorMessage.contains("Unable to find security group name") ) {
                throw new EC2ServiceException(ClientError.InvalidGroup_NotFound, "Specified Security Group does not exist" );
            } else if ( errorMessage.contains("Instance not found") ) {
                throw new EC2ServiceException(ClientError.InvalidInstanceID_NotFound,
                        "One or more of the specified instanceId not found");
            } else if ( errorMessage.contains("Cannot modify, instance should be in stopped state") ) {
                throw new EC2ServiceException(ClientError.IncorrectInstanceState,
                        "Unable to modify instance attribute. Specified instance is not in the correct state 'stopped'");
            } else {
                throw new EC2ServiceException( ServerError.InternalError, "An unexpected error occured");
            }
        }
    }
View Full Code Here

        String[] imageId = request.getParameterValues( "ImageId" );
        if ( null != imageId && 0 < imageId.length )
            image.setId( imageId[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
        }

        // -> execute the request
        DeregisterImageResponse EC2response = EC2SoapServiceImpl.toDeregisterImageResponse( ServiceProvider.getInstance().getEC2Engine().deregisterImage( image ));
        serializeResponse(response, EC2response);
View Full Code Here

        String[] instanceId = request.getParameterValues( "InstanceId" );
        if ( null != instanceId && 0 < instanceId.length )
            EC2request.setInstanceId( instanceId[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
        }

        String[] name = request.getParameterValues( "Name" );
        if ( null != name && 0 < name.length )
            EC2request.setName( name[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Name");
        }

        String[] description = request.getParameterValues( "Description" );
        if ( null != description && 0 < description.length ) {
            if (description[0].length() > 255)
                throw new EC2ServiceException( ClientError.InvalidParameterValue,
                        "Length of the value of parameter Description should be less than 255");
            EC2request.setDescription( description[0] );
        }

View Full Code Here

        String[] location = request.getParameterValues( "ImageLocation" );
        if ( null != location && 0 < location.length )
            EC2request.setLocation( location[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing parameter - ImageLocation");
        }

        String[] cloudRedfined = request.getParameterValues( "Architecture" );
        if ( null != cloudRedfined && 0 < cloudRedfined.length )
            EC2request.setArchitecture( cloudRedfined[0] );
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Architecture");
        }

        String[] name = request.getParameterValues( "Name" );
        if ( null != name && 0 < name.length )
            EC2request.setName( name[0] );
        else {
               throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Name");
        }

        String[] description = request.getParameterValues( "Description" );
        if ( null != description && 0 < description.length )
            EC2request.setDescription( description[0] );
View Full Code Here

       String[] imageId = request.getParameterValues( "ImageId" );
       if ( imageId != null && imageId.length > 0 )
            ec2request.setImageId( imageId[0]);
       else {
           throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
       }

        String[] description = request.getParameterValues( "Description.Value" );
        if ( description != null && description.length > 0 ) {
            ec2request.setAttribute(ImageAttribute.description);
            ec2request.setDescription(description[0]);
        } else {
            //add all launch permissions to ec2request
            ec2request = addLaunchPermImageAttribute(request, ec2request);
            if (ec2request.getLaunchPermissionSet().length > 0)
                ec2request.setAttribute(ImageAttribute.launchPermission);
            else {
                throw new EC2ServiceException( ClientError.MissingParamter,
                        "Missing required parameter - Description/LaunchPermission should be provided");
            }
        }

        // -> execute the request
View Full Code Here

TOP

Related Classes of com.cloud.bridge.service.exception.EC2ServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.