Skip to content

Commit a1331d1

Browse files
committed
Intermidiate checkin to Project feature:
1) Introduce new managers - ProjectManager and DomainManager. Moved all domain related code from AccountManager to DomainManager. 2) Moved some code from ManagementServerImpl to the correct managers. 3) New resource limit for Domain - Project
1 parent fdfb4d3 commit a1331d1

101 files changed

Lines changed: 3025 additions & 3421 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/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,6 @@ public class ApiConstants {
260260
public static final String TEMPLATE_TAG = "templatetag";
261261
public static final String HYPERVISOR_VERSION = "hypervisorversion";
262262
public static final String MAX_GUESTS_LIMIT = "maxguestslimit";
263+
public static final String PROJECT_ID = "projectid";
263264

264265
}

api/src/com/cloud/api/BaseCmd.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
import com.cloud.template.TemplateService;
5353
import com.cloud.user.Account;
5454
import com.cloud.user.AccountService;
55+
import com.cloud.user.DomainService;
56+
import com.cloud.user.ResourceLimitService;
5557
import com.cloud.user.UserContext;
5658
import com.cloud.utils.Pair;
5759
import com.cloud.utils.component.ComponentLocator;
@@ -68,7 +70,7 @@ public abstract class BaseCmd {
6870
public static final String RESPONSE_TYPE_JSON = "json";
6971

7072
public enum CommandType {
71-
BOOLEAN, DATE, FLOAT, INTEGER, LIST, LONG, OBJECT, MAP, STRING, TZDATE
73+
BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE
7274
}
7375

7476
// FIXME: Extract these out into a separate file
@@ -120,6 +122,8 @@ public enum CommandType {
120122
public static BareMetalVmService _bareMetalVmService;
121123
public static ProjectService _projectService;
122124
public static FirewallService _firewallService;
125+
public static DomainService _domainService;
126+
public static ResourceLimitService _resourceLimitService;
123127

124128
static void setComponents(ResponseGenerator generator) {
125129
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
@@ -143,6 +147,8 @@ static void setComponents(ResponseGenerator generator) {
143147
_bareMetalVmService = locator.getManager(BareMetalVmService.class);
144148
_projectService = locator.getManager(ProjectService.class);
145149
_firewallService = locator.getManager(FirewallService.class);
150+
_domainService = locator.getManager(DomainService.class);
151+
_resourceLimitService = locator.getManager(ResourceLimitService.class);
146152
}
147153

148154
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException;

api/src/com/cloud/api/commands/AssociateIPAddrCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Long getNetworkId() {
9898
if (zone.getNetworkType() == NetworkType.Advanced) {
9999
List<? extends Network> networks = _networkService.getVirtualNetworksOwnedByAccountInZone(getAccountName(), getDomainId(), getZoneId());
100100
if (networks.size() == 0) {
101-
String domain = _accountService.getDomain(getDomainId()).getName();
101+
String domain = _domainService.getDomain(getDomainId()).getName();
102102
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
103103
}
104104
assert (networks.size() <= 1) : "Too many virtual networks. This logic should be obsolete";

api/src/com/cloud/api/commands/CreateAccountCmd.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class CreateAccountCmd extends BaseCmd {
4444
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
4545
private String accountName;
4646

47-
@Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.LONG, required=true, description="Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin")
48-
private Long accountType;
47+
@Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.SHORT, required=true, description="Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin")
48+
private Short accountType;
4949

5050
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="Creates the user under the specified domain.")
5151
private Long domainId;
@@ -54,19 +54,19 @@ public class CreateAccountCmd extends BaseCmd {
5454
private String email;
5555

5656
@Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, required=true, description="firstname")
57-
private String firstname;
57+
private String firstName;
5858

5959
@Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, required=true, description="lastname")
60-
private String lastname;
60+
private String lastName;
6161

6262
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=true, description="Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.")
6363
private String password;
6464

6565
@Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, description="Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
66-
private String timezone;
66+
private String timeZone;
6767

6868
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="Unique username.")
69-
private String username;
69+
private String userName;
7070

7171
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the account's networks")
7272
private String networkDomain;
@@ -79,7 +79,7 @@ public String getAccountName() {
7979
return accountName;
8080
}
8181

82-
public Long getAccountType() {
82+
public Short getAccountType() {
8383
return accountType;
8484
}
8585

@@ -91,24 +91,24 @@ public String getEmail() {
9191
return email;
9292
}
9393

94-
public String getFirstname() {
95-
return firstname;
94+
public String getFirstName() {
95+
return firstName;
9696
}
9797

98-
public String getLastname() {
99-
return lastname;
98+
public String getLastName() {
99+
return lastName;
100100
}
101101

102102
public String getPassword() {
103103
return password;
104104
}
105105

106-
public String getTimezone() {
107-
return timezone;
106+
public String getTimeZone() {
107+
return timeZone;
108108
}
109109

110110
public String getUsername() {
111-
return username;
111+
return userName;
112112
}
113113

114114
public String getNetworkDomain() {
@@ -133,9 +133,9 @@ public long getEntityOwnerId() {
133133
@Override
134134
public void execute(){
135135
UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
136-
UserAccount user = _accountService.createAccount(this);
137-
if (user != null) {
138-
AccountResponse response = _responseGenerator.createUserAccountResponse(user);
136+
UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(), getDomainId(), getNetworkDomain());
137+
if (userAccount != null) {
138+
AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount);
139139
response.setResponseName(getCommandName());
140140
this.setResponseObject(response);
141141
} else {

api/src/com/cloud/api/commands/CreateDomainCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public long getEntityOwnerId() {
8181
@Override
8282
public void execute(){
8383
UserContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
84-
Domain domain = _accountService.createDomain(this);
84+
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
8585
if (domain != null) {
8686
DomainResponse response = _responseGenerator.createDomainResponse(domain);
8787
response.setResponseName(getCommandName());

api/src/com/cloud/api/commands/CreateProjectCmd.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ public class CreateProjectCmd extends BaseCmd {
5252
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="display text of the project")
5353
private String displayText;
5454

55-
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the zone id of the project")
56-
private Long zoneId;
57-
5855
/////////////////////////////////////////////////////
5956
/////////////////// Accessors ///////////////////////
6057
/////////////////////////////////////////////////////
@@ -75,10 +72,6 @@ public String getDisplayText() {
7572
return displayText;
7673
}
7774

78-
public Long getZoneId() {
79-
return zoneId;
80-
}
81-
8275
@Override
8376
public String getCommandName() {
8477
return s_name;
@@ -110,8 +103,8 @@ public long getEntityOwnerId() {
110103

111104
@Override
112105
public void execute(){
113-
UserContext.current().setEventDetails("Project Name: "+ getName() + ", zoneId " + zoneId);
114-
Project project = _projectService.createProject(getName(), getDisplayText(), getZoneId(), getAccountName(), getDomainId());
106+
UserContext.current().setEventDetails("Project Name: "+ getName());
107+
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
115108
if (project != null) {
116109
ProjectResponse response = _responseGenerator.createProjectResponse(project);
117110
response.setResponseName(getCommandName());

api/src/com/cloud/api/commands/CreateUserCmd.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ public String getEmail() {
8080
return email;
8181
}
8282

83-
public String getFirstname() {
83+
public String getFirstName() {
8484
return firstname;
8585
}
8686

87-
public String getLastname() {
87+
public String getLastName() {
8888
return lastname;
8989
}
9090

@@ -96,7 +96,7 @@ public String getTimezone() {
9696
return timezone;
9797
}
9898

99-
public String getUsername() {
99+
public String getUserName() {
100100
return username;
101101
}
102102

@@ -130,8 +130,8 @@ public long getEntityOwnerId() {
130130

131131
@Override
132132
public void execute(){
133-
UserContext.current().setEventDetails("UserName: "+getUsername()+", FirstName :"+getFirstname()+", LastName: "+getLastname());
134-
User user = _accountService.createUser(this);
133+
UserContext.current().setEventDetails("UserName: "+getUserName()+", FirstName :"+getFirstName()+", LastName: "+getLastName());
134+
User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
135135
if (user != null) {
136136
UserResponse response = _responseGenerator.createUserResponse(user);
137137
response.setResponseName(getCommandName());

api/src/com/cloud/api/commands/DeleteAccountCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public String getEventDescription() {
9191
@Override
9292
public void execute(){
9393
UserContext.current().setEventDetails("Account Id: "+getId());
94-
boolean result = _accountService.deleteUserAccount(this);
94+
boolean result = _accountService.deleteUserAccount(getId());
9595
if (result) {
9696
SuccessResponse response = new SuccessResponse(getCommandName());
9797
this.setResponseObject(response);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public String getEventDescription() {
9191
@Override
9292
public void execute(){
9393
UserContext.current().setEventDetails("Domain Id: "+getId());
94-
boolean result = _mgr.deleteDomain(this);
94+
boolean result = _domainService.deleteDomain(id, cleanup);
9595
if (result) {
9696
SuccessResponse response = new SuccessResponse(getCommandName());
9797
this.setResponseObject(response);

api/src/com/cloud/api/commands/DeleteProjectCmd.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@
2323
import com.cloud.api.ApiConstants;
2424
import com.cloud.api.BaseAsyncCmd;
2525
import com.cloud.api.BaseCmd;
26-
import com.cloud.api.BaseCmd.CommandType;
2726
import com.cloud.api.Implementation;
2827
import com.cloud.api.Parameter;
2928
import com.cloud.api.ServerApiException;
30-
import com.cloud.api.response.ProjectResponse;
3129
import com.cloud.api.response.SuccessResponse;
3230
import com.cloud.event.EventTypes;
3331
import com.cloud.exception.InvalidParameterValueException;
34-
import com.cloud.network.Network;
3532
import com.cloud.projects.Project;
3633
import com.cloud.user.UserContext;
3734

@@ -45,7 +42,7 @@ public class DeleteProjectCmd extends BaseAsyncCmd {
4542
//////////////// API parameters /////////////////////
4643
/////////////////////////////////////////////////////
4744

48-
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the project to be deleted")
45+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of the project to be deleted")
4946
private Long id;
5047

5148
/////////////////////////////////////////////////////
@@ -94,7 +91,7 @@ public long getEntityOwnerId() {
9491
if (project == null) {
9592
throw new InvalidParameterValueException("Project id=" + id + " doesn't exist");
9693
} else {
97-
return _projectService.getProject(id).getAccountId();
94+
return _projectService.getProject(id).getProjectAccountId();
9895
}
9996
}
10097
}

0 commit comments

Comments
 (0)