mirror of https://github.com/apache/cloudstack.git
Refactoring the delete zone cmd
This commit is contained in:
parent
c2f517fa81
commit
702658556b
|
|
@ -25,22 +25,19 @@ import java.util.Map;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@Implementation(method="deleteZone", manager=Manager.ConfigManager)
|
||||
public class DeleteZoneCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteZoneCmd.class.getName());
|
||||
|
||||
private static final String s_name = "deletezoneresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -66,35 +63,39 @@ public class DeleteZoneCmd extends BaseCmd {
|
|||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long zoneId = (Long) params.get(BaseCmd.Properties.ID.getName());
|
||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
|
||||
//verify input parameters
|
||||
DataCenterVO zone = getManagementServer().findDataCenterById(zoneId);
|
||||
if (zone == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find zone by id " + zoneId);
|
||||
}
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long zoneId = (Long) params.get(BaseCmd.Properties.ID.getName());
|
||||
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
//
|
||||
// if (userId == null) {
|
||||
// userId = Long.valueOf(User.UID_SYSTEM);
|
||||
// }
|
||||
//
|
||||
// //verify input parameters
|
||||
// DataCenterVO zone = getManagementServer().findDataCenterById(zoneId);
|
||||
// if (zone == null) {
|
||||
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find zone by id " + zoneId);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// getManagementServer().deleteZone(userId, zoneId);
|
||||
// } catch (Exception ex) {
|
||||
// s_logger.error("Exception deleting zone", ex);
|
||||
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||
// }
|
||||
//
|
||||
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
|
||||
//
|
||||
// return returnValues;
|
||||
// }
|
||||
|
||||
try {
|
||||
getManagementServer().deleteZone(userId, zoneId);
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception deleting zone", ex);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), "true"));
|
||||
|
||||
return returnValues;
|
||||
}
|
||||
@Override
|
||||
public String getResponse() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import com.cloud.api.commands.DeleteDiskOfferingCmd;
|
|||
import com.cloud.api.commands.DeletePodCmd;
|
||||
import com.cloud.api.commands.DeleteServiceOfferingCmd;
|
||||
import com.cloud.api.commands.DeleteVlanIpRangeCmd;
|
||||
import com.cloud.api.commands.DeleteZoneCmd;
|
||||
import com.cloud.api.commands.UpdateCfgCmd;
|
||||
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
||||
import com.cloud.api.commands.UpdatePodCmd;
|
||||
|
|
@ -207,7 +208,7 @@ public interface ConfigurationManager extends Manager {
|
|||
* @param userId
|
||||
* @param zoneId
|
||||
*/
|
||||
void deleteZone(long userId, long zoneId) throws InvalidParameterValueException, InternalErrorException;
|
||||
void deleteZone(DeleteZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException;
|
||||
|
||||
/**
|
||||
* Adds a VLAN to the database, along with an IP address range. Can add three types of VLANs: (1) zone-wide VLANs on the virtual public network (2) pod-wide direct attached VLANs (3) account-specific direct attached VLANs
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import com.cloud.api.commands.DeleteDiskOfferingCmd;
|
|||
import com.cloud.api.commands.DeletePodCmd;
|
||||
import com.cloud.api.commands.DeleteServiceOfferingCmd;
|
||||
import com.cloud.api.commands.DeleteVlanIpRangeCmd;
|
||||
import com.cloud.api.commands.DeleteZoneCmd;
|
||||
import com.cloud.api.commands.UpdateCfgCmd;
|
||||
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
||||
import com.cloud.api.commands.UpdatePodCmd;
|
||||
|
|
@ -735,7 +736,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
}
|
||||
|
||||
@DB
|
||||
public void deleteZone(long userId, long zoneId) throws InvalidParameterValueException, InternalErrorException {
|
||||
public void deleteZone(DeleteZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException {
|
||||
|
||||
Long userId = UserContext.current().getUserId();
|
||||
Long zoneId = cmd.getId();
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
|
||||
// Make sure the zone exists
|
||||
if (!validZone(zoneId)) {
|
||||
throw new InvalidParameterValueException("A zone with ID: " + zoneId + " does not exist.");
|
||||
|
|
|
|||
|
|
@ -991,7 +991,7 @@ public interface ManagementServer {
|
|||
* @param userId
|
||||
* @param zoneId
|
||||
*/
|
||||
void deleteZone(long userId, Long zoneId) throws InvalidParameterValueException, InternalErrorException;
|
||||
// void deleteZone(long userId, Long zoneId) throws InvalidParameterValueException, InternalErrorException;
|
||||
|
||||
/**
|
||||
* Change a pod's private IP range
|
||||
|
|
|
|||
|
|
@ -4370,10 +4370,10 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return _configMgr.createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteZone(long userId, Long zoneId) throws InvalidParameterValueException, InternalErrorException {
|
||||
_configMgr.deleteZone(userId, zoneId);
|
||||
}
|
||||
// @Override
|
||||
// public void deleteZone(long userId, Long zoneId) throws InvalidParameterValueException, InternalErrorException {
|
||||
// _configMgr.deleteZone(userId, zoneId);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String changePrivateIPRange(boolean add, Long podId, String startIP, String endIP) throws InvalidParameterValueException {
|
||||
|
|
|
|||
Loading…
Reference in New Issue