Search in sources :

Example 81 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DisassociateIPAddrCmd method execute.

@Override
public void execute() throws InsufficientAddressCapacityException {
    UserContext.current().setEventDetails("Ip Id: " + getIpAddressId());
    boolean result = _networkService.disassociateIpAddress(id);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disassociate ip address");
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 82 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class EnableAccountCmd method execute.

@Override
public void execute() {
    Account result = _accountService.enableAccount(getAccountName(), getDomainId(), getId());
    if (result != null) {
        AccountResponse response = _responseGenerator.createAccountResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable account");
    }
}
Also used : Account(com.cloud.user.Account) ServerApiException(com.cloud.api.ServerApiException) AccountResponse(com.cloud.api.response.AccountResponse)

Example 83 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class EnableStaticNatCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    try {
        boolean result = _rulesService.enableStaticNat(ipAddressId, virtualMachineId, false);
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable static nat");
        }
    } catch (NetworkRuleConflictException ex) {
        s_logger.info("Network rule conflict: " + ex.getMessage());
        s_logger.trace("Network Rule Conflict: ", ex);
        throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 84 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class ExtractIsoCmd method execute.

@Override
public void execute() {
    try {
        UserContext.current().setEventDetails(getEventDescription());
        Long uploadId = _templateService.extract(this);
        if (uploadId != null) {
            ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
            response.setResponseName(getCommandName());
            response.setObjectName("iso");
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract iso");
        }
    } catch (InternalErrorException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ExtractResponse(com.cloud.api.response.ExtractResponse) ServerApiException(com.cloud.api.ServerApiException) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 85 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class ExtractVolumeCmd method execute.

@Override
public void execute() {
    try {
        UserContext.current().setEventDetails("Volume Id: " + getId());
        Long uploadId = _mgr.extractVolume(this);
        if (uploadId != null) {
            Upload uploadInfo = _entityMgr.findById(Upload.class, uploadId);
            ExtractResponse response = new ExtractResponse();
            response.setResponseName(getCommandName());
            response.setObjectName("volume");
            response.setIdentityTableName("volumes");
            response.setId(id);
            response.setName(_entityMgr.findById(Volume.class, id).getName());
            response.setZoneId(zoneId);
            response.setZoneName(_entityMgr.findById(DataCenter.class, zoneId).getName());
            response.setMode(mode);
            response.setUploadId(uploadId);
            response.setState(uploadInfo.getUploadState().toString());
            response.setAccountId(getEntityOwnerId());
            response.setUrl(uploadInfo.getUploadUrl());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract volume");
        }
    } catch (URISyntaxException ex) {
        s_logger.info(ex);
        throw new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
    }
}
Also used : ExtractResponse(com.cloud.api.response.ExtractResponse) ServerApiException(com.cloud.api.ServerApiException) Upload(com.cloud.storage.Upload) URISyntaxException(java.net.URISyntaxException)

Aggregations

ServerApiException (com.cloud.api.ServerApiException)170 SuccessResponse (com.cloud.api.response.SuccessResponse)46 UserVm (com.cloud.uservm.UserVm)15 UserVmResponse (com.cloud.api.response.UserVmResponse)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 Account (com.cloud.user.Account)9 Host (com.cloud.host.Host)8 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)8 ListResponse (com.cloud.api.response.ListResponse)7 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)7 HostResponse (com.cloud.api.response.HostResponse)6 TemplateResponse (com.cloud.api.response.TemplateResponse)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 AccountResponse (com.cloud.api.response.AccountResponse)5 SystemVmResponse (com.cloud.api.response.SystemVmResponse)5 UserResponse (com.cloud.api.response.UserResponse)5 VolumeResponse (com.cloud.api.response.VolumeResponse)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5