mirror of https://github.com/apache/cloudstack.git
Refactoring deleteServiceOffering cmd
This commit is contained in:
parent
24db6ae24e
commit
9da6d89837
|
|
@ -18,28 +18,17 @@
|
|||
|
||||
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.service.ServiceOfferingVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
|
||||
@Implementation(method="deleteServiceOffering", manager=Manager.ConfigManager)
|
||||
public class DeleteServiceOfferingCmd extends BaseCmd{
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteServiceOfferingCmd.class.getName());
|
||||
private static final String s_name = "deleteserviceofferingresponse";
|
||||
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,42 +55,45 @@ public class DeleteServiceOfferingCmd extends BaseCmd{
|
|||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
@Override
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long offeringId = (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 service offering id
|
||||
ServiceOfferingVO offering = getManagementServer().findServiceOfferingById(offeringId);
|
||||
if (offering == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + offeringId);
|
||||
} else if (offering.getRemoved() != null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + offeringId);
|
||||
}
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long offeringId = (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 service offering id
|
||||
// ServiceOfferingVO offering = getManagementServer().findServiceOfferingById(offeringId);
|
||||
// if (offering == null) {
|
||||
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + offeringId);
|
||||
// } else if (offering.getRemoved() != null) {
|
||||
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + offeringId);
|
||||
// }
|
||||
//
|
||||
// boolean success = false;
|
||||
// try {
|
||||
// success = getManagementServer().deleteServiceOffering(userId, offeringId);
|
||||
// } catch (Exception ex) {
|
||||
// s_logger.error("Exception deleting service offering", ex);
|
||||
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete service offering " + offeringId + ": internal error.");
|
||||
// }
|
||||
//
|
||||
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
// if (success) {
|
||||
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.TRUE));
|
||||
// } else {
|
||||
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete serviceoffering " + offeringId);
|
||||
// }
|
||||
// return returnValues;
|
||||
// }
|
||||
|
||||
boolean success = false;
|
||||
try {
|
||||
success = getManagementServer().deleteServiceOffering(userId, offeringId);
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception deleting service offering", ex);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete service offering " + offeringId + ": internal error.");
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
if (success) {
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.TRUE));
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete serviceoffering " + offeringId);
|
||||
}
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResponse() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import com.cloud.api.commands.CreatePodCmd;
|
|||
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.UpdateCfgCmd;
|
||||
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
||||
import com.cloud.api.commands.UpdatePodCmd;
|
||||
|
|
@ -122,7 +123,7 @@ public interface ConfigurationManager extends Manager {
|
|||
* @param userId
|
||||
* @param serviceOfferingId
|
||||
*/
|
||||
boolean deleteServiceOffering(long userId, long serviceOfferingId) throws InvalidParameterValueException;
|
||||
boolean deleteServiceOffering(DeleteServiceOfferingCmd cmd) throws InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Creates a new disk offering
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import com.cloud.api.commands.CreatePodCmd;
|
|||
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.UpdateCfgCmd;
|
||||
import com.cloud.api.commands.UpdateDiskOfferingCmd;
|
||||
import com.cloud.api.commands.UpdatePodCmd;
|
||||
|
|
@ -1136,15 +1137,25 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
|||
}
|
||||
|
||||
|
||||
public boolean deleteServiceOffering(long userId, long serviceOfferingId) throws InvalidParameterValueException{
|
||||
ServiceOfferingVO offering = _serviceOfferingDao.findById(serviceOfferingId);
|
||||
public boolean deleteServiceOffering(DeleteServiceOfferingCmd cmd) throws InvalidParameterValueException{
|
||||
|
||||
Long offeringId = cmd.getId();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
|
||||
//Verify service offering id
|
||||
ServiceOfferingVO offering = _serviceOfferingDao.findById(offeringId);
|
||||
if (offering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find service offering by id " + serviceOfferingId);
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + offeringId);
|
||||
} else if (offering.getRemoved() != null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + offeringId);
|
||||
}
|
||||
|
||||
if (_serviceOfferingDao.remove(serviceOfferingId)) {
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully deleted service offering with name: " + offering.getName(), "soId=" + serviceOfferingId, "name=" + offering.getName(),
|
||||
if (_serviceOfferingDao.remove(offeringId)) {
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully deleted service offering with name: " + offering.getName(), "soId=" + offeringId, "name=" + offering.getName(),
|
||||
"displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == GuestIpType.Virtualized));
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue