use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.
the class CreateDomainCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Domain Name: " + getDomainName() + ((getParentDomainId() != null) ? ", Parent DomainId :" + getParentDomainId() : ""));
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
if (domain != null) {
DomainResponse response = _responseGenerator.createDomainResponse(domain);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create domain");
}
}
use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.
the class CreateLBStickinessPolicyCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
StickinessPolicy policy = null;
boolean success = false;
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
success = _lbService.applyLBStickinessPolicy(this);
if (success) {
// State might be different after the rule is applied, so get new object here
policy = _entityMgr.findById(StickinessPolicy.class, getEntityId());
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
setResponseObject(spResponse);
spResponse.setResponseName(getCommandName());
}
} finally {
if (!success || (policy == null)) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create stickiness policy ");
}
}
}
use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.
the class CreateLBStickinessPolicyCmd method create.
@Override
public void create() {
try {
StickinessPolicy result = _lbService.createLBStickinessPolicy(this);
this.setEntityId(result.getId());
} catch (NetworkRuleConflictException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
}
}
use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.
the class CreateLoadBalancerRuleCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
UserContext callerContext = UserContext.current();
boolean success = true;
LoadBalancer rule = null;
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
if (getOpenFirewall()) {
success = success && _firewallService.applyFirewallRules(getSourceIpAddressId(), callerContext.getCaller());
}
// State might be different after the rule is applied, so get new object here
rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
LoadBalancerResponse lbResponse = new LoadBalancerResponse();
if (rule != null) {
lbResponse = _responseGenerator.createLoadBalancerResponse(rule);
setResponseObject(lbResponse);
}
lbResponse.setResponseName(getCommandName());
} catch (Exception ex) {
s_logger.warn("Failed to create LB rule due to exception ", ex);
} finally {
if (!success || rule == null) {
if (getOpenFirewall()) {
_firewallService.revokeRelatedFirewallRule(getEntityId(), true);
}
// no need to apply the rule on the backend as it exists in the db only
_lbService.deleteLoadBalancerRule(getEntityId(), false);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create load balancer rule");
}
}
}
use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.
the class AssignVMCmd method execute.
@Override
public void execute() {
try {
UserVm userVm = _userVmService.moveVMToUser(this);
if (userVm == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm");
}
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
response.setResponseName(DeployVMCmd.getResultObjectName());
this.setResponseObject(response);
} catch (Exception e) {
e.printStackTrace();
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
}
}
Aggregations