Skip to content

Commit 7b0c5cf

Browse files
author
Alena Prokharchyk
committed
Removed unused methods from BaseCmd class. Moved some helper methods to AccountManagerImpl class
1 parent c257fb0 commit 7b0c5cf

44 files changed

Lines changed: 214 additions & 293 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/server/ManagementService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ public interface ManagementService {
269269
*/
270270
String generateRandomPassword();
271271

272-
public Long saveStartedEvent(Long userId, Long accountId, String type, String description, boolean startEventId, Long displayResourceEnabled);
273-
274-
public Long saveCompletedEvent(Long userId, Long accountId, String level, String type, String description, boolean displayResourceEnabled, long startEventId);
275-
276272
/**
277273
* Search registered key pairs for the logged in user.
278274
*

api/src/com/cloud/user/AccountService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ UserAccount createUserAccount(String userName, String password, String firstName
103103

104104
void checkAccess(Account account, AccessType accessType, boolean sameOwner, ControlledEntity... entities) throws PermissionDeniedException;
105105

106+
Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly);
107+
106108
}

api/src/org/apache/cloudstack/api/BaseAsyncCmd.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api;
1818

19-
import org.apache.cloudstack.context.CallContext;
20-
21-
import com.cloud.user.User;
2219

2320
/**
2421
* queryAsyncJobResult API command.
@@ -92,37 +89,4 @@ public Long getSyncObjId() {
9289
public Object getJob() {
9390
return job;
9491
}
95-
96-
protected long saveStartedEvent() {
97-
return saveStartedEvent(getEventType(), "Executing job for " + getEventDescription(), getStartEventId());
98-
}
99-
100-
protected long saveStartedEvent(String eventType, String description, Long startEventId) {
101-
CallContext ctx = CallContext.current();
102-
Long userId = ctx.getCallingUserId();
103-
userId = (userId == null) ? User.UID_SYSTEM : userId;
104-
Long startEvent = startEventId;
105-
if (startEvent == null) {
106-
startEvent = 0L;
107-
}
108-
return _mgr.saveStartedEvent((userId == null) ? User.UID_SYSTEM : userId, getEntityOwnerId(), eventType, description,
109-
isDisplayResourceEnabled(), startEvent);
110-
}
111-
112-
protected long saveCompletedEvent(String level, String description) {
113-
return saveCompletedEvent(level, getEventType(), description, getStartEventId());
114-
}
115-
116-
protected long saveCompletedEvent(String level, String eventType, String description, Long startEventId) {
117-
CallContext ctx = CallContext.current();
118-
Long userId = ctx.getCallingUserId();
119-
userId = (userId == null) ? User.UID_SYSTEM : userId;
120-
Long startEvent = startEventId;
121-
if (startEvent == null) {
122-
startEvent = 0L;
123-
}
124-
return _mgr.saveCompletedEvent((userId == null) ? User.UID_SYSTEM : userId, getEntityOwnerId(), level, eventType, description,
125-
isDisplayResourceEnabled(), startEvent);
126-
}
127-
12892
}

api/src/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,12 @@
3838
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
3939
import org.apache.cloudstack.query.QueryService;
4040
import org.apache.cloudstack.usage.UsageService;
41-
4241
import org.apache.log4j.Logger;
4342

4443
import com.cloud.configuration.ConfigurationService;
45-
import com.cloud.domain.Domain;
4644
import com.cloud.exception.ConcurrentOperationException;
4745
import com.cloud.exception.InsufficientCapacityException;
48-
import com.cloud.exception.InvalidParameterValueException;
4946
import com.cloud.exception.NetworkRuleConflictException;
50-
import com.cloud.exception.PermissionDeniedException;
5147
import com.cloud.exception.ResourceAllocationException;
5248
import com.cloud.exception.ResourceUnavailableException;
5349
import com.cloud.network.NetworkModel;
@@ -65,7 +61,6 @@
6561
import com.cloud.network.vpc.VpcService;
6662
import com.cloud.network.vpn.RemoteAccessVpnService;
6763
import com.cloud.network.vpn.Site2SiteVpnService;
68-
import com.cloud.projects.Project;
6964
import com.cloud.projects.ProjectService;
7065
import com.cloud.resource.ResourceService;
7166
import com.cloud.server.ManagementService;
@@ -88,36 +83,28 @@
8883

8984
public abstract class BaseCmd {
9085
private static final Logger s_logger = Logger.getLogger(BaseCmd.class.getName());
91-
92-
public static final String USER_ERROR_MESSAGE = "Internal error executing command, please contact your system administrator";
93-
public static final int PROGRESS_INSTANCE_CREATED = 1;
94-
9586
public static final String RESPONSE_TYPE_XML = "xml";
9687
public static final String RESPONSE_TYPE_JSON = "json";
97-
98-
public enum CommandType {
99-
BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID
100-
}
101-
10288
public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
10389
public static final DateFormat NEW_INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
90+
public static final String USER_ERROR_MESSAGE = "Internal error executing command, please contact your system administrator";
10491
public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+");
10592
private static final DateFormat s_outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
106-
10793
protected static final Map<Class<?>, List<Field>> fieldsForCmdClass = new HashMap<Class<?>, List<Field>>();
108-
109-
private Object _responseObject;
110-
private Map<String, String> fullUrlParams;
111-
112-
public enum HTTPMethod {
94+
public static enum HTTPMethod {
11395
GET, POST, PUT, DELETE
11496
}
97+
public static enum CommandType {
98+
BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID
99+
}
115100

101+
private Object _responseObject;
102+
private Map<String, String> fullUrlParams;
116103
private HTTPMethod httpMethod;
117-
118104
@Parameter(name = "response", type = CommandType.STRING)
119105
private String responseType;
120106

107+
121108
@Inject
122109
public ConfigurationService _configService;
123110
@Inject
@@ -174,7 +161,6 @@ public enum HTTPMethod {
174161
public NetworkACLService _networkACLService;
175162
@Inject
176163
public Site2SiteVpnService _s2sVpnService;
177-
178164
@Inject
179165
public QueryService _queryService;
180166
@Inject
@@ -282,10 +268,6 @@ public void setResponseObject(final Object responseObject) {
282268
_responseObject = responseObject;
283269
}
284270

285-
public ManagementService getMgmtServiceRef() {
286-
return _mgr;
287-
}
288-
289271
public static String getDateString(final Date date) {
290272
if (date == null) {
291273
return "";
@@ -318,10 +300,6 @@ protected List<Field> getAllFieldsForClass(final Class<?> clazz) {
318300
return filteredFields;
319301
}
320302

321-
protected Account getCurrentContextAccount() {
322-
return CallContext.current().getCallingAccount();
323-
}
324-
325303
/**
326304
* This method doesn't return all the @{link Parameter}, but only the ones exposed
327305
* and allowed for current @{link RoleType}. This method will get the fields for a given
@@ -334,7 +312,7 @@ protected Account getCurrentContextAccount() {
334312
public List<Field> getParamFields() {
335313
final List<Field> allFields = getAllFieldsForClass(this.getClass());
336314
final List<Field> validFields = new ArrayList<Field>();
337-
final Account caller = getCurrentContextAccount();
315+
final Account caller = CallContext.current().getCallingAccount();
338316

339317
for (final Field field : allFields) {
340318
final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
@@ -362,20 +340,6 @@ public List<Field> getParamFields() {
362340
return validFields;
363341
}
364342

365-
protected long getInstanceIdFromJobSuccessResult(final String result) {
366-
s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName());
367-
return 0;
368-
}
369-
370-
public static boolean isAdmin(final short accountType) {
371-
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) ||
372-
(accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
373-
}
374-
375-
public static boolean isRootAdmin(final short accountType) {
376-
return ((accountType == Account.ACCOUNT_TYPE_ADMIN));
377-
}
378-
379343
public void setFullUrlParams(final Map<String, String> map) {
380344
fullUrlParams = map;
381345
}
@@ -384,52 +348,6 @@ public Map<String, String> getFullUrlParams() {
384348
return fullUrlParams;
385349
}
386350

387-
public Long finalyzeAccountId(final String accountName, final Long domainId, final Long projectId, final boolean enabledOnly) {
388-
if (accountName != null) {
389-
if (domainId == null) {
390-
throw new InvalidParameterValueException("Account must be specified with domainId parameter");
391-
}
392-
393-
final Domain domain = _domainService.getDomain(domainId);
394-
if (domain == null) {
395-
throw new InvalidParameterValueException("Unable to find domain by id");
396-
}
397-
398-
final Account account = _accountService.getActiveAccountByName(accountName, domainId);
399-
if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
400-
if (!enabledOnly || account.getState() == Account.State.enabled) {
401-
return account.getId();
402-
} else {
403-
throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() +
404-
" as it's no longer active");
405-
}
406-
} else {
407-
// idList is not used anywhere, so removed it now
408-
//List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
409-
//idList.add(new IdentityProxy("domain", domainId, "domainId"));
410-
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain with specified id");
411-
}
412-
}
413-
414-
if (projectId != null) {
415-
final Project project = _projectService.getProject(projectId);
416-
if (project != null) {
417-
if (!enabledOnly || project.getState() == Project.State.Active) {
418-
return project.getProjectAccountId();
419-
} else {
420-
final PermissionDeniedException ex =
421-
new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() +
422-
" as it's no longer active");
423-
ex.addProxyObject(project.getUuid(), "projectId");
424-
throw ex;
425-
}
426-
} else {
427-
throw new InvalidParameterValueException("Unable to find project by id");
428-
}
429-
}
430-
return null;
431-
}
432-
433351
/**
434352
* To be overwritten by any class who needs specific validation
435353
*/

api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
import java.util.List;
2020

21-
import org.apache.log4j.Logger;
22-
2321
import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
2422
import org.apache.cloudstack.context.CallContext;
23+
import org.apache.log4j.Logger;
2524

2625
import com.cloud.template.VirtualMachineTemplate;
2726
import com.cloud.user.Account;
@@ -80,7 +79,7 @@ public void execute() {
8079
List<String> accountNames = _templateService.listTemplatePermissions(this);
8180

8281
Account account = CallContext.current().getCallingAccount();
83-
boolean isAdmin = (isAdmin(account.getType()));
82+
boolean isAdmin = (_accountService.isAdmin(account.getType()));
8483

8584
TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames, id, isAdmin);
8685
response.setResponseName(getCommandName());

api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.user;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiConstants;
2321
import org.apache.cloudstack.api.ApiErrorCode;
@@ -27,6 +25,7 @@
2725
import org.apache.cloudstack.api.response.DomainResponse;
2826
import org.apache.cloudstack.api.response.UserResponse;
2927
import org.apache.cloudstack.context.CallContext;
28+
import org.apache.log4j.Logger;
3029

3130
import com.cloud.user.Account;
3231
import com.cloud.user.User;
@@ -132,7 +131,7 @@ public String getCommandName() {
132131
@Override
133132
public long getEntityOwnerId() {
134133
Account account = CallContext.current().getCallingAccount();
135-
if ((account == null) || isAdmin(account.getType())) {
134+
if ((account == null) || _accountService.isAdmin(account.getType())) {
136135
if ((domainId != null) && (accountName != null)) {
137136
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
138137
if (userAccount != null) {

api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.affinitygroup;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.affinity.AffinityGroup;
2220
import org.apache.cloudstack.affinity.AffinityGroupResponse;
2321
import org.apache.cloudstack.api.APICommand;
@@ -29,6 +27,7 @@
2927
import org.apache.cloudstack.api.ServerApiException;
3028
import org.apache.cloudstack.api.response.DomainResponse;
3129
import org.apache.cloudstack.context.CallContext;
30+
import org.apache.log4j.Logger;
3231

3332
import com.cloud.event.EventTypes;
3433
import com.cloud.exception.ResourceAllocationException;
@@ -102,7 +101,7 @@ public String getCommandName() {
102101
@Override
103102
public long getEntityOwnerId() {
104103
Account account = CallContext.current().getCallingAccount();
105-
if ((account == null) || isAdmin(account.getType())) {
104+
if ((account == null) || _accountService.isAdmin(account.getType())) {
106105
if ((domainId != null) && (accountName != null)) {
107106
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
108107
if (userAccount != null) {

api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.affinitygroup;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.affinity.AffinityGroupResponse;
2220
import org.apache.cloudstack.api.APICommand;
2321
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -29,6 +27,7 @@
2927
import org.apache.cloudstack.api.response.DomainResponse;
3028
import org.apache.cloudstack.api.response.SuccessResponse;
3129
import org.apache.cloudstack.context.CallContext;
30+
import org.apache.log4j.Logger;
3231

3332
import com.cloud.event.EventTypes;
3433
import com.cloud.exception.InvalidParameterValueException;
@@ -105,7 +104,7 @@ public String getCommandName() {
105104
@Override
106105
public long getEntityOwnerId() {
107106
Account account = CallContext.current().getCallingAccount();
108-
if ((account == null) || isAdmin(account.getType())) {
107+
if ((account == null) || _accountService.isAdmin(account.getType())) {
109108
if ((domainId != null) && (accountName != null)) {
110109
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
111110
if (userAccount != null) {

api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.apache.cloudstack.api.command.user.autoscale;
1919

20-
import org.apache.log4j.Logger;
21-
2220
import org.apache.cloudstack.api.APICommand;
2321
import org.apache.cloudstack.api.ApiCommandJobType;
2422
import org.apache.cloudstack.api.ApiConstants;
@@ -30,6 +28,7 @@
3028
import org.apache.cloudstack.api.response.CounterResponse;
3129
import org.apache.cloudstack.api.response.DomainResponse;
3230
import org.apache.cloudstack.context.CallContext;
31+
import org.apache.log4j.Logger;
3332

3433
import com.cloud.event.EventTypes;
3534
import com.cloud.exception.ResourceAllocationException;
@@ -138,7 +137,7 @@ public String getEventType() {
138137

139138
@Override
140139
public long getEntityOwnerId() {
141-
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
140+
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
142141
if (accountId == null) {
143142
return CallContext.current().getCallingAccount().getId();
144143
}

api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.iso;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiCommandJobType;
2321
import org.apache.cloudstack.api.ApiConstants;
@@ -27,6 +25,7 @@
2725
import org.apache.cloudstack.api.response.TemplateResponse;
2826
import org.apache.cloudstack.api.response.ZoneResponse;
2927
import org.apache.cloudstack.context.CallContext;
28+
import org.apache.log4j.Logger;
3029

3130
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
3231
import com.cloud.user.Account;
@@ -120,7 +119,7 @@ public Boolean getShowRemoved() {
120119
public boolean listInReadyState() {
121120
Account account = CallContext.current().getCallingAccount();
122121
// It is account specific if account is admin type and domainId and accountName are not null
123-
boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
122+
boolean isAccountSpecific = (account == null || _accountService.isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
124123
// Show only those that are downloaded.
125124
TemplateFilter templateFilter = TemplateFilter.valueOf(getIsoFilter());
126125
boolean onlyReady =

0 commit comments

Comments
 (0)