use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class ListLBHealthCheckPoliciesCmd method execute.
@Override
public void execute() {
final List<LBHealthCheckResponse> hcpResponses = new ArrayList<>();
final ListResponse<LBHealthCheckResponse> response = new ListResponse<>();
Long lbRuleId = getLbRuleId();
final Long hId = getId();
if (lbRuleId == null) {
if (hId != null) {
lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
} else {
throw new InvalidParameterValueException("Either load balancer rule ID or health check policy ID should be specified");
}
}
final LoadBalancer lb = _lbService.findById(lbRuleId);
if (lb != null) {
final List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
final LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
hcpResponses.add(spResponse);
response.setResponses(hcpResponses);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class ListLBStickinessPoliciesCmd method execute.
@Override
public void execute() {
LoadBalancer lb = null;
if (lbRuleId == null && id == null) {
throw new InvalidParameterValueException("load balancer rule ID and stickiness policy ID can't be null");
}
if (id != null) {
lb = _lbService.findLbByStickinessId(id);
if (lb == null) {
throw new InvalidParameterValueException("stickiness policy ID doesn't exist");
}
if ((lbRuleId != null) && (lbRuleId != lb.getId())) {
throw new InvalidParameterValueException("stickiness policy ID doesn't belong to lbId" + lbRuleId);
}
}
if (lbRuleId != null && lb == null) {
lb = _lbService.findById(getLbRuleId());
}
final List<LBStickinessResponse> spResponses = new ArrayList<>();
final ListResponse<LBStickinessResponse> response = new ListResponse<>();
if (lb != null) {
// check permissions
final Account caller = CallContext.current().getCallingAccount();
_accountService.checkAccess(caller, null, true, lb);
final List<? extends StickinessPolicy> stickinessPolicies = _lbService.searchForLBStickinessPolicies(this);
final LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(stickinessPolicies, lb);
spResponses.add(spResponse);
response.setResponses(spResponses);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class UpdateLBStickinessPolicyCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final StickinessPolicy policy = _lbService.updateLBStickinessPolicy(this.getId(), this.getCustomId(), this.getDisplay());
final LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
final LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
setResponseObject(spResponse);
spResponse.setResponseName(getCommandName());
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class CertServiceImpl method listSslCerts.
@Override
public List<SslCertResponse> listSslCerts(final ListSslCertsCmd listSslCertCmd) {
final CallContext ctx = CallContext.current();
final Account caller = ctx.getCallingAccount();
final Long certId = listSslCertCmd.getCertId();
final Long accountId = listSslCertCmd.getAccountId();
final Long lbRuleId = listSslCertCmd.getLbId();
final Long projectId = listSslCertCmd.getProjectId();
final List<SslCertResponse> certResponseList = new ArrayList<>();
if (certId == null && accountId == null && lbRuleId == null && projectId == null) {
throw new InvalidParameterValueException("Invalid parameters either certificate ID or Account ID or Loadbalancer ID or Project ID required");
}
List<LoadBalancerCertMapVO> certLbMap = null;
SslCertVO certVO = null;
if (certId != null) {
certVO = _sslCertDao.findById(certId);
if (certVO == null) {
throw new InvalidParameterValueException("Invalid certificate id: " + certId);
}
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVO);
certLbMap = _lbCertDao.listByCertId(certId);
certResponseList.add(createCertResponse(certVO, certLbMap));
return certResponseList;
}
if (lbRuleId != null) {
final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, lbRuleId);
if (lb == null) {
throw new InvalidParameterValueException("Found no loadbalancer with id: " + lbRuleId);
}
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, lb);
// get the cert id
final LoadBalancerCertMapVO lbCertMapRule;
lbCertMapRule = _lbCertDao.findByLbRuleId(lbRuleId);
if (lbCertMapRule == null) {
s_logger.debug("No certificate bound to loadbalancer id: " + lbRuleId);
return certResponseList;
}
certVO = _sslCertDao.findById(lbCertMapRule.getCertId());
certLbMap = _lbCertDao.listByCertId(lbCertMapRule.getCertId());
certResponseList.add(createCertResponse(certVO, certLbMap));
return certResponseList;
}
if (projectId != null) {
final Project project = _projectMgr.getProject(projectId);
if (project == null) {
throw new InvalidParameterValueException("Found no project with id: " + projectId);
}
final List<SslCertVO> projectCertVOList = _sslCertDao.listByAccountId(project.getProjectAccountId());
if (projectCertVOList == null || projectCertVOList.isEmpty()) {
return certResponseList;
}
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, projectCertVOList.get(0));
for (final SslCertVO cert : projectCertVOList) {
certLbMap = _lbCertDao.listByCertId(cert.getId());
certResponseList.add(createCertResponse(cert, certLbMap));
}
return certResponseList;
}
// reached here look by accountId
final List<SslCertVO> certVOList = _sslCertDao.listByAccountId(accountId);
if (certVOList == null || certVOList.isEmpty()) {
return certResponseList;
}
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVOList.get(0));
for (final SslCertVO cert : certVOList) {
certLbMap = _lbCertDao.listByCertId(cert.getId());
certResponseList.add(createCertResponse(cert, certLbMap));
}
return certResponseList;
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class CertServiceImpl method createCertResponse.
public SslCertResponse createCertResponse(final SslCertVO cert, final List<LoadBalancerCertMapVO> lbCertMap) {
final SslCertResponse response = new SslCertResponse();
final Account account = _accountDao.findByIdIncludingRemoved(cert.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
// find the project
final Project project = _projectMgr.findByProjectAccountIdIncludingRemoved(account.getId());
if (project != null) {
response.setProjectId(project.getUuid());
response.setProjectName(project.getName());
} else {
response.setAccountName(account.getAccountName());
}
} else {
response.setAccountName(account.getAccountName());
}
final DomainVO domain = _domainDao.findByIdIncludingRemoved(cert.getDomainId());
response.setDomainId(domain.getUuid());
response.setDomainName(domain.getName());
response.setObjectName("sslcert");
response.setId(cert.getUuid());
response.setCertificate(cert.getCertificate());
response.setFingerprint(cert.getFingerPrint());
if (cert.getChain() != null) {
response.setCertchain(cert.getChain());
}
if (lbCertMap != null && !lbCertMap.isEmpty()) {
final List<String> lbIds = new ArrayList<>();
for (final LoadBalancerCertMapVO mapVO : lbCertMap) {
final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, mapVO.getLbId());
if (lb != null) {
lbIds.add(lb.getUuid());
}
}
response.setLbIds(lbIds);
}
return response;
}
Aggregations