Search in sources :

Example 1 with AutoScaleVmGroupVO

use of com.cloud.network.as.AutoScaleVmGroupVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method configureLbAutoScaleVmGroup.

@Override
@DB
public boolean configureLbAutoScaleVmGroup(final long vmGroupid, String currentState) throws ResourceUnavailableException {
    final AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
    boolean success = false;
    final LoadBalancerVO loadBalancer = _lbDao.findById(vmGroup.getLoadBalancerId());
    FirewallRule.State backupState = loadBalancer.getState();
    if (vmGroup.getState().equals(AutoScaleVmGroup.State_New)) {
        loadBalancer.setState(FirewallRule.State.Add);
        _lbDao.persist(loadBalancer);
    } else if (loadBalancer.getState() == FirewallRule.State.Active && vmGroup.getState().equals(AutoScaleVmGroup.State_Revoke)) {
        loadBalancer.setState(FirewallRule.State.Add);
        _lbDao.persist(loadBalancer);
    }
    try {
        success = applyAutoScaleConfig(loadBalancer, vmGroup, currentState);
    } catch (ResourceUnavailableException e) {
        s_logger.warn("Unable to configure AutoScaleVmGroup to the lb rule: " + loadBalancer.getId() + " because resource is unavaliable:", e);
        if (isRollBackAllowedForProvider(loadBalancer)) {
            loadBalancer.setState(backupState);
            _lbDao.persist(loadBalancer);
            s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup");
        }
        throw e;
    } finally {
        if (!success) {
            s_logger.warn("Failed to configure LB Auto Scale Vm Group with Id:" + vmGroupid);
        }
    }
    if (success) {
        if (vmGroup.getState().equals(AutoScaleVmGroup.State_New)) {
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(TransactionStatus status) {
                    loadBalancer.setState(FirewallRule.State.Active);
                    s_logger.debug("LB rule " + loadBalancer.getId() + " state is set to Active");
                    _lbDao.persist(loadBalancer);
                    vmGroup.setState(AutoScaleVmGroup.State_Enabled);
                    _autoScaleVmGroupDao.persist(vmGroup);
                    s_logger.debug("LB Auto Scale Vm Group with Id: " + vmGroupid + " is set to Enabled state.");
                }
            });
        }
        s_logger.info("Successfully configured LB Autoscale Vm Group with Id: " + vmGroupid);
    }
    return success;
}
Also used : AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) FirewallRule(com.cloud.network.rules.FirewallRule) DB(com.cloud.utils.db.DB)

Example 2 with AutoScaleVmGroupVO

use of com.cloud.network.as.AutoScaleVmGroupVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLoadBalancerRuleToApply.

private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) {
    List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
    Ip sourceIp = getSourceIp(lb);
    LbSslCert sslCert = getLbSslCert(lb.getId());
    LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp, sslCert, lb.getLbProtocol());
    if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(lb.getId())) {
        // Get the associated VmGroup
        AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.listByAll(lb.getId(), null).get(0);
        LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, vmGroup.getState(), lb);
        loadBalancing.setAutoScaleVmGroup(lbAutoScaleVmGroup);
    } else {
        List<LbDestination> dstList = getExistingDestinations(lb.getId());
        loadBalancing.setDestinations(dstList);
        List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
        loadBalancing.setHealthCheckPolicies(hcPolicyList);
    }
    return loadBalancing;
}
Also used : LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Example 3 with AutoScaleVmGroupVO

use of com.cloud.network.as.AutoScaleVmGroupVO in project cloudstack by apache.

the class ApiDBUtils method findJobInstanceUuid.

public static String findJobInstanceUuid(AsyncJob job) {
    if (job == null) {
        return null;
    }
    String jobInstanceId = null;
    ApiCommandJobType jobInstanceType = EnumUtils.fromString(ApiCommandJobType.class, job.getInstanceType(), ApiCommandJobType.None);
    if (job.getInstanceId() == null) {
        // when assert is hit, implement 'getInstanceId' of BaseAsyncCmd and return appropriate instance id
        assert (false);
        return null;
    }
    if (jobInstanceType == ApiCommandJobType.Volume) {
        VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
        if (volume != null) {
            jobInstanceId = volume.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
        VMTemplateVO template = ApiDBUtils.findTemplateById(job.getInstanceId());
        if (template != null) {
            jobInstanceId = template.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.VirtualMachine || jobInstanceType == ApiCommandJobType.ConsoleProxy || jobInstanceType == ApiCommandJobType.SystemVm || jobInstanceType == ApiCommandJobType.DomainRouter) {
        VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
        if (vm != null) {
            jobInstanceId = vm.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Snapshot) {
        Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
        if (snapshot != null) {
            jobInstanceId = snapshot.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Host) {
        Host host = ApiDBUtils.findHostById(job.getInstanceId());
        if (host != null) {
            jobInstanceId = host.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.StoragePool) {
        StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
        if (spool != null) {
            jobInstanceId = spool.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.IpAddress) {
        IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
        if (ip != null) {
            jobInstanceId = ip.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.SecurityGroup) {
        SecurityGroup sg = ApiDBUtils.findSecurityGroupById(job.getInstanceId());
        if (sg != null) {
            jobInstanceId = sg.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
        PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
        if (pnet != null) {
            jobInstanceId = pnet.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.TrafficType) {
        PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
        if (trafficType != null) {
            jobInstanceId = trafficType.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
        PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
        if (sp != null) {
            jobInstanceId = sp.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
        FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
        if (fw != null) {
            jobInstanceId = fw.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Account) {
        Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
        if (acct != null) {
            jobInstanceId = acct.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.User) {
        User usr = ApiDBUtils.findUserById(job.getInstanceId());
        if (usr != null) {
            jobInstanceId = usr.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
        StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
        if (route != null) {
            jobInstanceId = route.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
        VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
        if (gateway != null) {
            jobInstanceId = gateway.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Counter) {
        CounterVO counter = ApiDBUtils.getCounter(job.getInstanceId());
        if (counter != null) {
            jobInstanceId = counter.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Condition) {
        ConditionVO condition = ApiDBUtils.findConditionById(job.getInstanceId());
        if (condition != null) {
            jobInstanceId = condition.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.AutoScalePolicy) {
        AutoScalePolicyVO policy = ApiDBUtils.findAutoScalePolicyById(job.getInstanceId());
        if (policy != null) {
            jobInstanceId = policy.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.AutoScaleVmProfile) {
        AutoScaleVmProfileVO profile = ApiDBUtils.findAutoScaleVmProfileById(job.getInstanceId());
        if (profile != null) {
            jobInstanceId = profile.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.AutoScaleVmGroup) {
        AutoScaleVmGroupVO group = ApiDBUtils.findAutoScaleVmGroupById(job.getInstanceId());
        if (group != null) {
            jobInstanceId = group.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Network) {
        NetworkVO networkVO = ApiDBUtils.findNetworkById(job.getInstanceId());
        if (networkVO != null) {
            jobInstanceId = networkVO.getUuid();
        }
    } else if (jobInstanceType != ApiCommandJobType.None) {
        // entity table mapping
        assert (false);
    }
    return jobInstanceId;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) AutoScalePolicyVO(com.cloud.network.as.AutoScalePolicyVO) VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ApiCommandJobType(org.apache.cloudstack.api.ApiCommandJobType) User(com.cloud.user.User) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) StaticRouteVO(com.cloud.network.vpc.StaticRouteVO) SecurityGroup(com.cloud.network.security.SecurityGroup) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) AutoScaleVmProfileVO(com.cloud.network.as.AutoScaleVmProfileVO) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) VolumeVO(com.cloud.storage.VolumeVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ConditionVO(com.cloud.network.as.ConditionVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) CounterVO(com.cloud.network.as.CounterVO)

Aggregations

AutoScaleVmGroupVO (com.cloud.network.as.AutoScaleVmGroupVO)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Host (com.cloud.host.Host)1 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)1 PublicIp (com.cloud.network.addr.PublicIp)1 AutoScalePolicyVO (com.cloud.network.as.AutoScalePolicyVO)1 AutoScaleVmProfileVO (com.cloud.network.as.AutoScaleVmProfileVO)1 ConditionVO (com.cloud.network.as.ConditionVO)1 CounterVO (com.cloud.network.as.CounterVO)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkTrafficTypeVO (com.cloud.network.dao.PhysicalNetworkTrafficTypeVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 LbAutoScaleVmGroup (com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup)1 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)1 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)1 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)1 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)1 FirewallRule (com.cloud.network.rules.FirewallRule)1