bug 8659: deleteNetwork is async now

status 8659: resolved fixed
This commit is contained in:
alena 2011-02-23 15:11:59 -08:00
parent 63cff8de26
commit 6424042cac
4 changed files with 58 additions and 23 deletions

View File

@ -21,15 +21,19 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.Network;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a network", responseObject=SuccessResponse.class)
public class DeleteNetworkCmd extends BaseCmd{
public class DeleteNetworkCmd extends BaseAsyncCmd{
public static final Logger s_logger = Logger.getLogger(DeleteNetworkOfferingCmd.class.getName());
private static final String s_name = "deletenetworkresponse";
@ -70,4 +74,35 @@ public class DeleteNetworkCmd extends BaseCmd{
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete network");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}
@Override
public Long getSyncObjId() {
return id;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_DELETE;
}
@Override
public String getEventDescription() {
return "Deleting network: " + id;
}
@Override
public long getEntityOwnerId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
} else {
return _networkService.getNetwork(id).getAccountId();
}
}
}

View File

@ -53,23 +53,6 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getEventDescription() {
return "Restarting network: " + getNetworkId();
}
public String getEventType() {
return EventTypes.NETWORK_RESTART;
}
public long getEntityOwnerId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
} else {
return _networkService.getNetwork(id).getAccountId();
}
}
public Long getNetworkId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
@ -105,7 +88,6 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
@ -115,4 +97,23 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return id;
}
public String getEventDescription() {
return "Restarting network: " + getNetworkId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_RESTART;
}
@Override
public long getEntityOwnerId() {
Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
} else {
return _networkService.getNetwork(id).getAccountId();
}
}
}

View File

@ -179,7 +179,7 @@ public class EventTypes {
public static final String EVENT_VPN_USER_REMOVE = "VPN.USER.REMOVE";
//Network
public static final String NETWORK_RESTART = "NETWORK.RESTART";
public static final String EVENT_NETWORK_RESTART = "NETWORK.RESTART";
//Custom certificates
public static final String EVENT_UPLOAD_CUSTOM_CERTIFICATE = "UPLOAD.CUSTOM.CERTIFICATE";

View File

@ -1757,8 +1757,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return networks;
}
@Override
@ActionEvent (eventType=EventTypes.EVENT_NETWORK_DELETE, eventDescription="deleting network")
@Override @ActionEvent (eventType=EventTypes.EVENT_NETWORK_DELETE, eventDescription="deleting network", async=true)
public boolean deleteNetwork(long networkId){
//Don't allow to delete network via api call when it has vms assigned to it
int nicCount = getActiveNicsInNetwork(networkId);
@ -2022,7 +2021,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
@Override
@Override @ActionEvent (eventType=EventTypes.EVENT_NETWORK_RESTART, eventDescription="restarting network", async=true)
public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
// This method restarts all network elements belonging to the network
Long networkId = cmd.getNetworkId();