use of com.cloud.api.response.LoadBalancerResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createLoadBalancerResponse.
@Override
public LoadBalancerResponse createLoadBalancerResponse(final LoadBalancer loadBalancer) {
final LoadBalancerResponse lbResponse = new LoadBalancerResponse();
lbResponse.setId(loadBalancer.getUuid());
lbResponse.setName(loadBalancer.getName());
lbResponse.setDescription(loadBalancer.getDescription());
final List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(loadBalancer.getId());
lbResponse.setCidrList(StringUtils.join(cidrs, ","));
final IPAddressVO publicIp = ApiDBUtils.findIpAddressById(loadBalancer.getSourceIpAddressId());
lbResponse.setPublicIpId(publicIp.getUuid());
lbResponse.setPublicIp(publicIp.getAddress().addr());
lbResponse.setPublicPort(Integer.toString(loadBalancer.getSourcePortStart()));
lbResponse.setPrivatePort(Integer.toString(loadBalancer.getDefaultPortStart()));
lbResponse.setAlgorithm(loadBalancer.getAlgorithm());
lbResponse.setLbProtocol(loadBalancer.getLbProtocol());
lbResponse.setForDisplay(loadBalancer.isDisplay());
lbResponse.setClientTimeout(loadBalancer.getClientTimeout());
lbResponse.setServerTimeout(loadBalancer.getServerTimeout());
final FirewallRule.State state = loadBalancer.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
stateToSet = "Deleting";
}
lbResponse.setState(stateToSet);
populateOwner(lbResponse, loadBalancer);
final DataCenter zone = ApiDBUtils.findZoneById(publicIp.getDataCenterId());
if (zone != null) {
lbResponse.setZoneId(zone.getUuid());
}
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, loadBalancer.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
if (tagResponse != null) {
tagResponses.add(tagResponse);
}
}
lbResponse.setTags(tagResponses);
final Network ntwk = ApiDBUtils.findNetworkById(loadBalancer.getNetworkId());
lbResponse.setNetworkId(ntwk.getUuid());
lbResponse.setObjectName("loadbalancer");
return lbResponse;
}
use of com.cloud.api.response.LoadBalancerResponse 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");
}
}
}
Aggregations