Search in sources :

Example 11 with LoadBalancer

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);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) LBHealthCheckResponse(com.cloud.api.response.LBHealthCheckResponse)

Example 12 with LoadBalancer

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);
}
Also used : Account(com.cloud.legacymodel.user.Account) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Example 13 with LoadBalancer

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());
}
Also used : LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Example 14 with LoadBalancer

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;
}
Also used : Account(com.cloud.legacymodel.user.Account) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) CallContext(com.cloud.context.CallContext) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) SslCertVO(com.cloud.network.dao.SslCertVO) SslCertResponse(com.cloud.api.response.SslCertResponse)

Example 15 with LoadBalancer

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;
}
Also used : Account(com.cloud.legacymodel.user.Account) Project(com.cloud.projects.Project) DomainVO(com.cloud.domain.DomainVO) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) SslCertResponse(com.cloud.api.response.SslCertResponse)

Aggregations

LoadBalancer (com.cloud.legacymodel.network.LoadBalancer)15 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)9 ServerApiException (com.cloud.api.ServerApiException)5 ArrayList (java.util.ArrayList)5 Account (com.cloud.legacymodel.user.Account)4 LBHealthCheckResponse (com.cloud.api.response.LBHealthCheckResponse)3 LBStickinessResponse (com.cloud.api.response.LBStickinessResponse)3 ListResponse (com.cloud.api.response.ListResponse)3 LoadBalancerResponse (com.cloud.api.response.LoadBalancerResponse)3 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)3 NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)3 HealthCheckPolicy (com.cloud.network.rules.HealthCheckPolicy)3 StickinessPolicy (com.cloud.network.rules.StickinessPolicy)3 SslCertResponse (com.cloud.api.response.SslCertResponse)2 CallContext (com.cloud.context.CallContext)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)2 LoadBalancerCertMapVO (com.cloud.network.dao.LoadBalancerCertMapVO)2 Project (com.cloud.projects.Project)2 DomainVO (com.cloud.domain.DomainVO)1 ActionEvent (com.cloud.event.ActionEvent)1