cloudstack/server/src/com/cloud/network/rules/FirewallRules.java

99 lines
3.7 KiB
Java

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.LoadBalancerVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.utils.net.Ip;
public class FirewallRules extends RuleApplier {
@Inject
NetworkModel _networkModel;
@Inject
LoadBalancingRulesManager _lbMgr;
@Inject
LoadBalancerDao _loadBalancerDao;
private final List<? extends FirewallRule> rules;
private List<LoadBalancingRule> loadbalancingRules;
private Purpose purpose;
public FirewallRules(final Network network, final List<? extends FirewallRule> rules) {
super(network);
this.rules = rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
purpose = rules.get(0).getPurpose();
if (purpose == Purpose.LoadBalancing) {
// for load balancer we have to resend all lb rules for the network
final List<LoadBalancerVO> lbs = _loadBalancerDao.listByNetworkIdAndScheme(network.getId(), Scheme.Public);
loadbalancingRules = new ArrayList<LoadBalancingRule>();
for (final LoadBalancerVO lb : lbs) {
final List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
final List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
final List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
final LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId());
final Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
loadbalancingRules.add(loadBalancing);
}
}
return visitor.visit(this);
}
public List<? extends FirewallRule> getRules() {
return rules;
}
public List<LoadBalancingRule> getLoadbalancingRules() {
return loadbalancingRules;
}
public Purpose getPurpose() {
return purpose;
}
}