Bug: CS-15443, Fix for NPE while adding Firewall Rule

This commit is contained in:
Jayapal 2012-07-04 16:13:32 +05:30
parent 38befcd228
commit f05115a9c4
2 changed files with 6 additions and 4 deletions

View File

@ -33,6 +33,7 @@ import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.NetworkACL;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.net.NetUtils;
@ -117,13 +118,13 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
public void execute() throws ResourceUnavailableException {
UserContext callerContext = UserContext.current();
boolean success = false;
FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId());
FirewallRule rule = _entityMgr.findById(NetworkACL.class, getEntityId());
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
success = _firewallService.applyFirewallRules(rule.getSourceIpAddressId(), callerContext.getCaller());
// State is different after the rule is applied, so get new object here
rule = _entityMgr.findById(FirewallRule.class, getEntityId());
rule = _entityMgr.findById(NetworkACL.class, getEntityId());
FirewallResponse fwResponse = new FirewallResponse();
if (rule != null) {
fwResponse = _responseGenerator.createFirewallResponse(rule);

View File

@ -27,6 +27,7 @@ import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.NetworkACL;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a firewall rule", responseObject=SuccessResponse.class)
@ -75,11 +76,11 @@ public class DeleteFirewallRuleCmd extends BaseAsyncCmd {
@Override
public long getEntityOwnerId() {
if (ownerId == null) {
FirewallRule rule = _entityMgr.findById(FirewallRule.class, id);
FirewallRule rule = _entityMgr.findById(NetworkACL.class, id);
if (rule == null) {
throw new InvalidParameterValueException("Unable to find firewall rule by id=" + id);
} else {
ownerId = _entityMgr.findById(FirewallRule.class, id).getAccountId();
ownerId = _entityMgr.findById(NetworkACL.class, id).getAccountId();
}
}
return ownerId;