use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class LoadBalancingRulesManagerImpl method updateLBHealthChecks.
// This method will check the status of services which has monitors created
// by CloudStack and update them in lbvmmap table
@DB
@Override
public void updateLBHealthChecks(Scheme scheme) throws ResourceUnavailableException {
List<LoadBalancerVO> rules = _lbDao.listAll();
List<NetworkVO> networks = _networkDao.listAll();
List<LoadBalancerTO> stateRules = null;
boolean isHandled = false;
for (NetworkVO ntwk : networks) {
Network network = _networkDao.findById(ntwk.getId());
String capability = getLBCapability(network.getId(), Capability.HealthCheckPolicy.getName());
if (capability != null && capability.equalsIgnoreCase("true")) {
/*
* s_logger.debug(
* "HealthCheck Manager :: LB Provider in the Network has the Healthcheck policy capability :: "
* + provider.get(0).getName());
*/
rules = _lbDao.listByNetworkIdAndScheme(network.getId(), scheme);
if (rules != null && rules.size() > 0) {
List<LoadBalancingRule> lbrules = new ArrayList<LoadBalancingRule>();
for (LoadBalancerVO lb : rules) {
List<LbDestination> dstList = getExistingDestinations(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
// hashealtChecks
if (hcPolicyList != null && hcPolicyList.size() > 0) {
Ip sourceIp = getSourceIp(lb);
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, null, hcPolicyList, sourceIp, null, lb.getLbProtocol());
lbrules.add(loadBalancing);
}
}
if (lbrules.size() > 0) {
isHandled = false;
for (LoadBalancingServiceProvider lbElement : _lbProviders) {
stateRules = lbElement.updateHealthChecks(network, lbrules);
if (stateRules != null && stateRules.size() > 0) {
for (LoadBalancerTO lbto : stateRules) {
LoadBalancerVO ulb = _lbDao.findByUuid(lbto.getUuid());
List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(ulb.getId());
for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(ulb.getNetworkId(), vm.getId());
String dstIp = lbVmMap.getInstanceIp() == null ? nic.getIPv4Address() : lbVmMap.getInstanceIp();
for (int i = 0; i < lbto.getDestinations().length; i++) {
LoadBalancerTO.DestinationTO des = lbto.getDestinations()[i];
if (dstIp.equalsIgnoreCase(lbto.getDestinations()[i].getDestIp())) {
lbVmMap.setState(des.getMonitorState());
_lb2VmMapDao.persist(lbVmMap);
s_logger.debug("Updating the LB VM Map table with the service state");
}
}
}
}
isHandled = true;
}
if (isHandled) {
break;
}
}
}
}
} else {
// s_logger.debug("HealthCheck Manager :: LB Provider in the Network DNOT the Healthcheck policy capability ");
}
}
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class CommandSetupHelper method createFirewallRulesCommands.
public void createFirewallRulesCommands(final List<? extends FirewallRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
final List<FirewallRuleTO> rulesTO = new ArrayList<FirewallRuleTO>();
String systemRule = null;
Boolean defaultEgressPolicy = false;
if (rules != null) {
if (rules.size() > 0) {
if (rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress && rules.get(0).getType() == FirewallRule.FirewallRuleType.System) {
systemRule = String.valueOf(FirewallRule.FirewallRuleType.System);
}
}
for (final FirewallRule rule : rules) {
_rulesDao.loadSourceCidrs((FirewallRuleVO) rule);
final FirewallRule.TrafficType traffictype = rule.getTrafficType();
if (traffictype == FirewallRule.TrafficType.Ingress) {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, sourceIp.getAddress().addr(), Purpose.Firewall, traffictype);
rulesTO.add(ruleTO);
} else if (rule.getTrafficType() == FirewallRule.TrafficType.Egress) {
final NetworkVO network = _networkDao.findById(guestNetworkId);
final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
defaultEgressPolicy = offering.getEgressDefaultPolicy();
assert rule.getSourceIpAddressId() == null : "ipAddressId should be null for egress firewall rule. ";
final FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, "", Purpose.Firewall, traffictype, defaultEgressPolicy);
rulesTO.add(ruleTO);
}
}
}
final SetFirewallRulesCommand cmd = new SetFirewallRulesCommand(rulesTO);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
if (systemRule != null) {
cmd.setAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT, systemRule);
} else {
cmd.setAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT, String.valueOf(defaultEgressPolicy));
}
cmds.addCommand(cmd);
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class GuestNetworkGuru method implement.
@Override
public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert network.getState() == State.Implementing : "Why are we implementing " + network;
final long dcId = dest.getDataCenter().getId();
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
// physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
final NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
allocateVnet(network, implemented, dcId, physicalNetworkId, context.getReservationId());
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
return implemented;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class PodBasedNetworkGuru method design.
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
TrafficType type = offering.getTrafficType();
if (!isMyTrafficType(type)) {
return null;
}
NetworkVO config = new NetworkVO(type, Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
return config;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class PrivateNetworkGuru method design.
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
DataCenter dc = _entityMgr.findById(DataCenter.class, plan.getDataCenterId());
if (!canHandle(offering, dc)) {
return null;
}
BroadcastDomainType broadcastType;
if (userSpecified != null) {
broadcastType = userSpecified.getBroadcastDomainType();
} else {
broadcastType = BroadcastDomainType.Vlan;
}
NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, broadcastType, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
throw new InvalidParameterValueException("cidr and gateway must be specified together.");
}
if (userSpecified.getCidr() != null) {
network.setCidr(userSpecified.getCidr());
network.setGateway(userSpecified.getGateway());
} else {
throw new InvalidParameterValueException("Can't design network " + network + "; netmask/gateway must be passed in");
}
if (offering.getSpecifyVlan()) {
network.setBroadcastUri(userSpecified.getBroadcastUri());
network.setState(State.Setup);
}
} else {
throw new CloudRuntimeException("Can't design network " + network + "; netmask/gateway must be passed in");
}
return network;
}
Aggregations