Refactoring the delete vlan ip range cmd

This commit is contained in:
abhishek 2010-08-25 10:59:14 -07:00
parent 5a8313cc51
commit c2f517fa81
5 changed files with 56 additions and 46 deletions

View File

@ -18,29 +18,18 @@
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
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.exception.InvalidParameterValueException;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.api.BaseCmd.Manager;
@Implementation(method="deleteVlanIpRange", manager=Manager.ConfigManager)
public class DeleteVlanIpRangeCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(DeleteVlanIpRangeCmd.class.getName());
private static final String s_name = "deletevlaniprangeresponse";
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 /////////////////////
@ -65,31 +54,35 @@ public class DeleteVlanIpRangeCmd extends BaseCmd {
public String getName() {
return s_name;
}
public List<Pair<Enum, Boolean>> getProperties() {
return s_properties;
}
}
@Override
public String getResponse() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Pair<String, Object>> execute(Map<String, Object> params) {
Long vlanDbId = (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);
}
// Delete the VLAN and its public IP addresses
boolean success = false;
try {
success = getManagementServer().deleteVlanAndPublicIpRange(userId, vlanDbId);
} catch (InvalidParameterValueException ex) {
s_logger.error("Exception deleting VLAN", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VLAN: " + ex.getMessage());
}
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), success));
return returnValues;
}
// @Override
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
// Long vlanDbId = (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);
// }
//
// // Delete the VLAN and its public IP addresses
// boolean success = false;
// try {
// success = getManagementServer().deleteVlanAndPublicIpRange(userId, vlanDbId);
// } catch (InvalidParameterValueException ex) {
// s_logger.error("Exception deleting VLAN", ex);
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VLAN: " + ex.getMessage());
// }
//
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), success));
// return returnValues;
// }
}

View File

@ -26,6 +26,7 @@ import com.cloud.api.commands.CreateServiceOfferingCmd;
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.UpdateCfgCmd;
import com.cloud.api.commands.UpdateDiskOfferingCmd;
import com.cloud.api.commands.UpdatePodCmd;
@ -232,6 +233,7 @@ public interface ConfigurationManager extends Manager {
* @return success/failure
*/
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException;
boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd) throws InvalidParameterValueException;
/**
* Adds/deletes private IPs

View File

@ -40,6 +40,7 @@ import com.cloud.api.commands.CreateServiceOfferingCmd;
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.UpdateCfgCmd;
import com.cloud.api.commands.UpdateDiskOfferingCmd;
import com.cloud.api.commands.UpdatePodCmd;
@ -1924,5 +1925,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
s_logger.error("Unable to add the new config entry:",ex);
return false;
}
}
@Override
public boolean deleteVlanAnIpRange(DeleteVlanIpRangeCmd cmd) throws InvalidParameterValueException {
Long vlanDbId = cmd.getId();
Long userId = UserContext.current().getUserId();
if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM);
}
return deleteVlanAndPublicIpRange(userId, vlanDbId);
}
}

View File

@ -468,7 +468,7 @@ public interface ManagementServer {
* @param vlanDbId
* @return success/failure
*/
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException;
// boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException;
/**
* Searches for vlan by the specified search criteria

View File

@ -1828,10 +1828,10 @@ public class ManagementServerImpl implements ManagementServer {
return _configMgr.createVlanAndPublicIpRange(userId, vlanType, zoneId, accountId, podId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
}
@Override
public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException {
return _configMgr.deleteVlanAndPublicIpRange(userId, vlanDbId);
}
// @Override
// public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException {
// return _configMgr.deleteVlanAndPublicIpRange(userId, vlanDbId);
// }
@Override
public VolumeVO createVolume(long userId, long accountId, String name, long zoneId, long diskOfferingId, long startEventId, long size) throws InternalErrorException {