Skip to content

Commit a53cb4a

Browse files
author
Kris McQueen
committed
Refactoring deleteDomain to new API framework. Cleaning up some compilation errors that resulted from previous refactoring, namely there was a requirement to keep the old manager method around for createDiskOffering and createZone in order for the ConfigurationServer to work.
1 parent dbb2897 commit a53cb4a

9 files changed

Lines changed: 147 additions & 178 deletions

File tree

core/src/com/cloud/network/security/dao/NetworkGroupRulesDao.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,4 @@ public interface NetworkGroupRulesDao extends GenericDao<NetworkGroupRulesVO, Lo
2626
* @return the list of network groups with associated ingress rules
2727
*/
2828
List<NetworkGroupRulesVO> listNetworkGroupRules();
29-
30-
/**
31-
* List network groups and associated ingress rules for a particular domain
32-
* @param domainId the id of the domain for which to list groups and associated rules
33-
* @param recursive whether or not to recursively search the domain for network groups
34-
* @return the list of network groups with associated ingress rules
35-
*/
36-
List<NetworkGroupRulesVO> listNetworkGroupRulesByDomain(long domainId, boolean recursive);
3729
}

core/src/com/cloud/network/security/dao/NetworkGroupRulesDaoImpl.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
import javax.ejb.Local;
66

7-
import com.cloud.domain.DomainVO;
87
import com.cloud.domain.dao.DomainDao;
98
import com.cloud.network.security.NetworkGroupRulesVO;
10-
import com.cloud.server.ManagementServer;
11-
import com.cloud.utils.component.ComponentLocator;
129
import com.cloud.utils.db.Filter;
1310
import com.cloud.utils.db.GenericDaoBase;
1411
import com.cloud.utils.db.SearchBuilder;
@@ -58,34 +55,4 @@ public List<NetworkGroupRulesVO> listNetworkGroupRules(long accountId) {
5855

5956
return listActiveBy(sc, searchFilter);
6057
}
61-
62-
@Override
63-
public List<NetworkGroupRulesVO> listNetworkGroupRulesByDomain(long domainId, boolean recursive) {
64-
65-
if (_domainDao == null) {
66-
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
67-
_domainDao = locator.getDao(DomainDao.class);
68-
69-
DomainSearch = createSearchBuilder();
70-
DomainSearch.and("domainId", DomainSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
71-
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
72-
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
73-
DomainSearch.join("domainSearch", domainSearch, DomainSearch.entity().getDomainId(), domainSearch.entity().getId());
74-
DomainSearch.done();
75-
}
76-
77-
Filter searchFilter = new Filter(NetworkGroupRulesVO.class, "id", true, null, null);
78-
SearchCriteria<NetworkGroupRulesVO> sc = DomainSearch.create();
79-
80-
if (!recursive) {
81-
sc.setParameters("domainId", domainId);
82-
}
83-
84-
DomainVO domain = _domainDao.findById(domainId);
85-
if (domain != null) {
86-
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
87-
}
88-
89-
return listActiveBy(sc, searchFilter);
90-
}
9158
}

core/src/com/cloud/serializer/SerializerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static Object fromSerializedString(String result) {
6969
}
7070
return null;
7171
} catch(RuntimeException e) {
72-
s_logger.error("Caught runtime exception when doing GSON descrialization on: " + result);
72+
s_logger.error("Caught runtime exception when doing GSON deserialization on: " + result);
7373
throw e;
7474
}
7575
}

server/src/com/cloud/api/commands/DeleteDomainCmd.java

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,18 @@
1818

1919
package com.cloud.api.commands;
2020

21-
import java.util.ArrayList;
22-
import java.util.List;
23-
import java.util.Map;
24-
2521
import org.apache.log4j.Logger;
2622

27-
import com.cloud.api.BaseCmd;
23+
import com.cloud.api.BaseAsyncCmd;
24+
import com.cloud.api.Implementation;
2825
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 {
3531
public static final Logger s_logger = Logger.getLogger(DeleteDomainCmd.class.getName());
3632
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-
}
4433

4534
/////////////////////////////////////////////////////
4635
//////////////// API parameters /////////////////////
@@ -73,43 +62,15 @@ public Boolean getCleanup() {
7362
@Override
7463
public String getName() {
7564
return s_name;
76-
}
77-
@Override
78-
public List<Pair<Enum, Boolean>> getProperties() {
79-
return s_properties;
80-
}
65+
}
8166

8267
@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();
8770

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);
11073

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);
11475
}
11576
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.cloud.api.response;
2+
3+
import com.cloud.api.ResponseObject;
4+
import com.cloud.serializer.Param;
5+
6+
public class DeleteDomainResponse implements ResponseObject {
7+
@Param(name="result")
8+
private String result;
9+
10+
public String getResult() {
11+
return result;
12+
}
13+
14+
public void setResult(String result) {
15+
this.result = result;
16+
}
17+
}

server/src/com/cloud/configuration/ConfigurationManager.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,18 @@ public interface ConfigurationManager extends Manager {
141141
* @return ID
142142
*/
143143
DiskOfferingVO createDiskOffering(CreateDiskOfferingCmd cmd) throws InvalidParameterValueException;
144-
144+
145+
/**
146+
* Creates a new disk offering
147+
* @param domainId
148+
* @param name
149+
* @param description
150+
* @param numGibibytes
151+
* @param tags
152+
* @return newly created disk offering
153+
*/
154+
DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException;
155+
145156
/**
146157
* Creates a new pod
147158
* @param userId
@@ -193,7 +204,23 @@ public interface ConfigurationManager extends Manager {
193204
* @throws InternalErrorException
194205
*/
195206
DataCenterVO createZone(CreateZoneCmd cmd) throws InvalidParameterValueException, InternalErrorException;
196-
207+
208+
/**
209+
* Creates a new zone
210+
* @param userId
211+
* @param zoneName
212+
* @param dns1
213+
* @param dns2
214+
* @param internalDns1
215+
* @param internalDns2
216+
* @param vnetRange
217+
* @param guestCidr
218+
* @return
219+
* @throws InvalidParameterValueException
220+
* @throws InternalErrorException
221+
*/
222+
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr) throws InvalidParameterValueException, InternalErrorException;
223+
197224
/**
198225
* Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone.
199226
* @param UpdateZoneCmd

0 commit comments

Comments
 (0)