Search in sources :

Example 11 with ServerApiException

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

the class DeleteClusterCmd method execute.

@Override
public void execute() {
    boolean result = _resourceService.deleteCluster(this);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete cluster");
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 12 with ServerApiException

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

the class CreateLoadBalancerRuleCmd method create.

@Override
public void create() {
    //cidr list parameter is deprecated
    if (cidrlist != null) {
        throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
    }
    try {
        LoadBalancer result = _lbService.createLoadBalancerRule(this, getOpenFirewall());
        this.setEntityId(result.getId());
    } catch (NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    } catch (InsufficientAddressCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) LoadBalancer(com.cloud.network.rules.LoadBalancer) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 13 with ServerApiException

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

the class CreatePodCmd method execute.

@Override
public void execute() {
    Pod result = _configService.createPod(getZoneId(), getPodName(), getStartIp(), getEndIp(), getGateway(), getNetmask(), getAllocationState());
    if (result != null) {
        PodResponse response = _responseGenerator.createPodResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create pod");
    }
}
Also used : Pod(com.cloud.dc.Pod) ServerApiException(com.cloud.api.ServerApiException) PodResponse(com.cloud.api.response.PodResponse)

Example 14 with ServerApiException

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

the class CreatePortForwardingRuleCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    UserContext callerContext = UserContext.current();
    boolean success = true;
    PortForwardingRule rule = null;
    try {
        UserContext.current().setEventDetails("Rule Id: " + getEntityId());
        if (getOpenFirewall()) {
            success = success && _firewallService.applyFirewallRules(ipAddressId, callerContext.getCaller());
        }
        success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCaller());
        // State is different after the rule is applied, so get new object here
        rule = _entityMgr.findById(PortForwardingRule.class, getEntityId());
        FirewallRuleResponse fwResponse = new FirewallRuleResponse();
        if (rule != null) {
            fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);
            setResponseObject(fwResponse);
        }
        fwResponse.setResponseName(getCommandName());
    } finally {
        if (!success || rule == null) {
            if (getOpenFirewall()) {
                _firewallService.revokeRelatedFirewallRule(getEntityId(), true);
            }
            _rulesService.revokePortForwardingRule(getEntityId(), true);
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to apply port forwarding rule");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) UserContext(com.cloud.user.UserContext) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) FirewallRuleResponse(com.cloud.api.response.FirewallRuleResponse)

Example 15 with ServerApiException

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

the class CreateProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    Project project = _projectService.enableProject(this.getEntityId());
    if (project != null) {
        ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(com.cloud.api.response.ProjectResponse) 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