|
| 1 | +// Copyright 2012 Citrix Systems, Inc. Licensed under the |
| 2 | +// Apache License, Version 2.0 (the "License"); you may not use this |
| 3 | +// file except in compliance with the License. Citrix Systems, Inc. |
| 4 | +// reserves all rights not expressly granted by the License. |
| 5 | +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// Unless required by applicable law or agreed to in writing, software |
| 7 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +// See the License for the specific language governing permissions and |
| 10 | +// limitations under the License. |
| 11 | +// |
| 12 | +// Automatically generated by addcopyright.py at 04/03/2012 |
| 13 | +package com.cloud.api.commands; |
| 14 | + |
| 15 | +/** |
| 16 | + * @author Alena Prokharchyk |
| 17 | + */ |
| 18 | +import org.apache.log4j.Logger; |
| 19 | + |
| 20 | +import com.cloud.api.ApiConstants; |
| 21 | +import com.cloud.api.BaseAsyncCmd; |
| 22 | +import com.cloud.api.BaseCmd; |
| 23 | +import com.cloud.api.IdentityMapper; |
| 24 | +import com.cloud.api.Implementation; |
| 25 | +import com.cloud.api.Parameter; |
| 26 | +import com.cloud.api.ServerApiException; |
| 27 | +import com.cloud.api.response.SuccessResponse; |
| 28 | +import com.cloud.async.AsyncJob; |
| 29 | +import com.cloud.event.EventTypes; |
| 30 | +import com.cloud.exception.InvalidParameterValueException; |
| 31 | +import com.cloud.exception.ResourceUnavailableException; |
| 32 | +import com.cloud.network.rules.NetworkACL; |
| 33 | +import com.cloud.user.UserContext; |
| 34 | + |
| 35 | +@Implementation(description="Deletes a Network ACL", responseObject=SuccessResponse.class) |
| 36 | +public class DeleteNetworkACLCmd extends BaseAsyncCmd { |
| 37 | + public static final Logger s_logger = Logger.getLogger(DeleteNetworkACLCmd.class.getName()); |
| 38 | + private static final String s_name = "deletenetworkaclresponse"; |
| 39 | + |
| 40 | + ///////////////////////////////////////////////////// |
| 41 | + //////////////// API parameters ///////////////////// |
| 42 | + ///////////////////////////////////////////////////// |
| 43 | + |
| 44 | + @IdentityMapper(entityTableName="firewall_rules") |
| 45 | + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network ACL") |
| 46 | + private Long id; |
| 47 | + |
| 48 | + // unexposed parameter needed for events logging |
| 49 | + @IdentityMapper(entityTableName="account") |
| 50 | + @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false) |
| 51 | + private Long ownerId; |
| 52 | + ///////////////////////////////////////////////////// |
| 53 | + /////////////////// Accessors /////////////////////// |
| 54 | + ///////////////////////////////////////////////////// |
| 55 | + |
| 56 | + public Long getId() { |
| 57 | + return id; |
| 58 | + } |
| 59 | + |
| 60 | + ///////////////////////////////////////////////////// |
| 61 | + /////////////// API Implementation/////////////////// |
| 62 | + ///////////////////////////////////////////////////// |
| 63 | + @Override |
| 64 | + public String getCommandName() { |
| 65 | + return s_name; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public String getEventType() { |
| 70 | + return EventTypes.EVENT_FIREWALL_CLOSE; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public String getEventDescription() { |
| 75 | + return ("Deleting Network ACL id=" + id); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public long getEntityOwnerId() { |
| 80 | + if (ownerId == null) { |
| 81 | + NetworkACL rule = _networkACLService.getNetworkACL(id); |
| 82 | + if (rule == null) { |
| 83 | + throw new InvalidParameterValueException("Unable to find network ACL by id=" + id); |
| 84 | + } else { |
| 85 | + ownerId = rule.getAccountId(); |
| 86 | + } |
| 87 | + } |
| 88 | + return ownerId; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void execute() throws ResourceUnavailableException { |
| 93 | + UserContext.current().setEventDetails("Network ACL Id: " + id); |
| 94 | + boolean result = _networkACLService.revokeNetworkACL(id, true); |
| 95 | + |
| 96 | + if (result) { |
| 97 | + SuccessResponse response = new SuccessResponse(getCommandName()); |
| 98 | + this.setResponseObject(response); |
| 99 | + } else { |
| 100 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network ACL"); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + |
| 105 | + @Override |
| 106 | + public String getSyncObjType() { |
| 107 | + return BaseAsyncCmd.networkSyncObject; |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public Long getSyncObjId() { |
| 112 | + return _firewallService.getFirewallRule(id).getNetworkId(); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public AsyncJob.Type getInstanceType() { |
| 117 | + return AsyncJob.Type.FirewallRule; |
| 118 | + } |
| 119 | +} |
| 120 | + |
0 commit comments