|
18 | 18 |
|
19 | 19 | package com.cloud.api.commands; |
20 | 20 |
|
21 | | -import java.util.ArrayList; |
22 | | -import java.util.List; |
23 | | -import java.util.Map; |
24 | | - |
25 | 21 | import org.apache.log4j.Logger; |
26 | 22 |
|
27 | | -import com.cloud.api.BaseCmd; |
| 23 | +import com.cloud.api.BaseAsyncCmd; |
| 24 | +import com.cloud.api.Implementation; |
28 | 25 | import com.cloud.api.Parameter; |
29 | | -import com.cloud.api.ServerApiException; |
30 | | -import com.cloud.domain.DomainVO; |
31 | | -import com.cloud.user.Account; |
32 | | -import com.cloud.utils.Pair; |
33 | | - |
34 | | -public class DeleteDomainCmd extends BaseCmd{ |
| 26 | +import com.cloud.api.response.DeleteDomainResponse; |
| 27 | +import com.cloud.serializer.SerializerHelper; |
| 28 | + |
| 29 | +@Implementation(method="deleteDomain") |
| 30 | +public class DeleteDomainCmd extends BaseAsyncCmd { |
35 | 31 | public static final Logger s_logger = Logger.getLogger(DeleteDomainCmd.class.getName()); |
36 | 32 | private static final String s_name = "deletedomainresponse"; |
37 | | - private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>(); |
38 | | - |
39 | | - static { |
40 | | - s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); |
41 | | - s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE)); |
42 | | - s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.CLEANUP, Boolean.FALSE)); |
43 | | - } |
44 | 33 |
|
45 | 34 | ///////////////////////////////////////////////////// |
46 | 35 | //////////////// API parameters ///////////////////// |
@@ -73,43 +62,15 @@ public Boolean getCleanup() { |
73 | 62 | @Override |
74 | 63 | public String getName() { |
75 | 64 | return s_name; |
76 | | - } |
77 | | - @Override |
78 | | - public List<Pair<Enum, Boolean>> getProperties() { |
79 | | - return s_properties; |
80 | | - } |
| 65 | + } |
81 | 66 |
|
82 | 67 | @Override |
83 | | - public List<Pair<String, Object>> execute(Map<String, Object> params) { |
84 | | - Long domainId = (Long)params.get(BaseCmd.Properties.ID.getName()); |
85 | | - Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); |
86 | | - Boolean cleanup = (Boolean)params.get(BaseCmd.Properties.CLEANUP.getName()); |
| 68 | + public String getResponse() { |
| 69 | + String deleteResult = (String)getResponseObject(); |
87 | 70 |
|
88 | | - // If account is null, consider System as an owner for this action |
89 | | - if (account == null) { |
90 | | - account = getManagementServer().findAccountById(Long.valueOf(1L)); |
91 | | - } |
92 | | - |
93 | | - if ((domainId.longValue() == DomainVO.ROOT_DOMAIN) || !getManagementServer().isChildDomain(account.getDomainId(), domainId)) { |
94 | | - throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to delete domain " + domainId + ", permission denied."); |
95 | | - } |
96 | | - |
97 | | - // check if domain exists in the system |
98 | | - DomainVO domain = getManagementServer().findDomainIdById(domainId); |
99 | | - if (domain == null) { |
100 | | - throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find domain " + domainId); |
101 | | - } |
102 | | - |
103 | | - long jobId = getManagementServer().deleteDomainAsync(domainId, account.getId(), cleanup); // default owner is 'system' |
104 | | - if (jobId == 0) { |
105 | | - s_logger.warn("Unable to schedule async-job for DeleteDomain comamnd"); |
106 | | - } else { |
107 | | - if (s_logger.isDebugEnabled()) |
108 | | - s_logger.debug("DeleteDomain command has been accepted, job id: " + jobId); |
109 | | - } |
| 71 | + DeleteDomainResponse response = new DeleteDomainResponse(); |
| 72 | + response.setResult(deleteResult); |
110 | 73 |
|
111 | | - List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>(); |
112 | | - returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId))); |
113 | | - return returnValues; |
| 74 | + return SerializerHelper.toSerializedString(response); |
114 | 75 | } |
115 | 76 | } |
0 commit comments