Search in sources :

Example 21 with ServerApiException

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

the class AttachVolumeCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    Volume result = _userVmService.attachVolumeToVM(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 22 with ServerApiException

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

the class AuthorizeSecurityGroupIngressCmd method execute.

@Override
public void execute() {
    if (cidrList != null) {
        for (String cidr : cidrList) {
            if (!NetUtils.isValidCIDR(cidr)) {
                throw new ServerApiException(BaseCmd.PARAM_ERROR, cidr + " is an Invalid CIDR ");
            }
        }
    }
    List<? extends SecurityRule> ingressRules = _securityGroupService.authorizeSecurityGroupIngress(this);
    if (ingressRules != null && !ingressRules.isEmpty()) {
        SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponseFromSecurityGroupRule(ingressRules);
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to authorize security group ingress rule(s)");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) SecurityGroupResponse(com.cloud.api.response.SecurityGroupResponse)

Example 23 with ServerApiException

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

the class AddSecondaryStorageCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Host> result = _resourceService.discoverHosts(this);
        HostResponse hostResponse = null;
        if (result != null && result.size() > 0) {
            for (Host host : result) {
                // There should only be one secondary storage host per add
                hostResponse = _responseGenerator.createHostResponse(host);
                hostResponse.setResponseName(getCommandName());
                hostResponse.setObjectName("secondarystorage");
                this.setResponseObject(hostResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add secondary storage");
        }
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) HostResponse(com.cloud.api.response.HostResponse) Host(com.cloud.host.Host) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 24 with ServerApiException

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

the class AddTrafficTypeCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("TrafficType Id: " + getEntityId());
    PhysicalNetworkTrafficType result = _networkService.getPhysicalNetworkTrafficType(getEntityId());
    if (result != null) {
        TrafficTypeResponse response = _responseGenerator.createTrafficTypeResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add traffic type to physical network");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) TrafficTypeResponse(com.cloud.api.response.TrafficTypeResponse) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 25 with ServerApiException

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

the class AddVpnUserCmd method create.

@Override
public void create() {
    Account owner = _accountService.getAccount(getEntityOwnerId());
    VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password);
    if (vpnUser == null) {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
    }
    setEntityId(vpnUser.getId());
}
Also used : Account(com.cloud.user.Account) VpnUser(com.cloud.network.VpnUser) ServerApiException(com.cloud.api.ServerApiException)

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