Skip to content

Commit 3fd17ae

Browse files
author
prachi
committed
Merge awsapi related changes to CloudStack
1 parent bc7dbd7 commit 3fd17ae

File tree

11 files changed

+187
-14
lines changed

11 files changed

+187
-14
lines changed

api/src/com/cloud/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public class ApiConstants {
333333
public static final String HA_HOST = "hahost";
334334
public static final String CUSTOM_DISK_OFF_MAX_SIZE = "customdiskofferingmaxsize";
335335

336+
public static final String DEFAULT_ZONE_ID = "defaultzoneid";
336337

337338
public enum HostDetails {
338339
all, capacity, events, stats, min;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
14+
package com.cloud.api.commands;
15+
16+
import org.apache.log4j.Logger;
17+
18+
import com.cloud.api.BaseAsyncCmd;
19+
import com.cloud.api.Implementation;
20+
import com.cloud.api.Parameter;
21+
import com.cloud.api.ApiConstants;
22+
import com.cloud.api.IdentityMapper;
23+
import com.cloud.user.Account;
24+
import com.cloud.event.EventTypes;
25+
import com.cloud.async.AsyncJob;
26+
import com.cloud.api.response.AccountResponse;
27+
import com.cloud.api.ServerApiException;
28+
import com.cloud.api.BaseCmd;
29+
30+
@Implementation(description="Marks a default zone for this account", responseObject=AccountResponse.class, since="3.0.3")
31+
public class MarkDefaultZoneForAccountCmd extends BaseAsyncCmd {
32+
public static final Logger s_logger = Logger.getLogger(MarkDefaultZoneForAccountCmd.class.getName());
33+
34+
private static final String s_name = "markdefaultzoneforaccountresponse";
35+
36+
/////////////////////////////////////////////////////
37+
////////////////API parameters //////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@IdentityMapper(entityTableName="account")
41+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="Name of the account that is to be marked.")
42+
private String accountName;
43+
44+
@IdentityMapper(entityTableName="domain")
45+
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, required=true, description="Marks the account that belongs to the specified domain.")
46+
private Long domainId;
47+
48+
@IdentityMapper(entityTableName="data_center")
49+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="The Zone ID with which the account is to be marked.")
50+
private Long defaultZoneId;
51+
52+
/////////////////////////////////////////////////////
53+
/////////////////// Accessors ///////////////////////
54+
/////////////////////////////////////////////////////
55+
56+
public String getAccountName() {
57+
return accountName;
58+
}
59+
60+
public Long getDomainId() {
61+
return domainId;
62+
}
63+
64+
public Long getDefaultZoneId() {
65+
return defaultZoneId;
66+
}
67+
68+
/////////////////////////////////////////////////////
69+
/////////////// API Implementation///////////////////
70+
/////////////////////////////////////////////////////
71+
72+
@Override
73+
public String getCommandName() {
74+
return s_name;
75+
}
76+
77+
@Override
78+
public long getEntityOwnerId() {
79+
return Account.ACCOUNT_ID_SYSTEM;
80+
}
81+
82+
@Override
83+
public String getEventType() {
84+
return EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE;
85+
}
86+
87+
@Override
88+
public String getEventDescription() {
89+
return "Marking account with the default zone: " + getDefaultZoneId();
90+
}
91+
92+
@Override
93+
public AsyncJob.Type getInstanceType() {
94+
return AsyncJob.Type.Account;
95+
}
96+
97+
@Override
98+
public void execute(){
99+
Account result = _configService.markDefaultZone(getAccountName(),getDomainId(), getDefaultZoneId());
100+
if (result != null) {
101+
AccountResponse response = _responseGenerator.createAccountResponse(result);
102+
response.setResponseName(getCommandName());
103+
this.setResponseObject(response);
104+
}
105+
else {
106+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to mark the account with the default zone");
107+
}
108+
}
109+
}
110+

api/src/com/cloud/api/response/AccountResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class AccountResponse extends BaseResponse {
3535

3636
@SerializedName(ApiConstants.DOMAIN) @Param(description="name of the Domain the account belongs too")
3737
private String domainName;
38+
39+
@SerializedName(ApiConstants.DEFAULT_ZONE_ID) @Param(description="the default zone of the account")
40+
private IdentityProxy defaultZoneId = new IdentityProxy("data_center");
3841

3942
@SerializedName(ApiConstants.RECEIVED_BYTES) @Param(description="the total number of network traffic bytes received")
4043
private Long bytesReceived;
@@ -266,4 +269,8 @@ public void setNetworkTotal(Long networkTotal) {
266269
public void setNetworkAvailable(String networkAvailable) {
267270
this.networkAvailable = networkAvailable;
268271
}
272+
273+
public void setDefaultZone(Long defaultZoneId) {
274+
this.defaultZoneId.setValue(defaultZoneId);
275+
}
269276
}

api/src/com/cloud/configuration/ConfigurationService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.api.commands.LDAPConfigCmd;
3131
import com.cloud.api.commands.LDAPRemoveCmd;
3232
import com.cloud.api.commands.ListNetworkOfferingsCmd;
33+
import com.cloud.api.commands.MarkDefaultZoneForAccountCmd;
3334
import com.cloud.api.commands.UpdateCfgCmd;
3435
import com.cloud.api.commands.UpdateDiskOfferingCmd;
3536
import com.cloud.api.commands.UpdateNetworkOfferingCmd;
@@ -216,6 +217,17 @@ public interface ConfigurationService {
216217
*/
217218
Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException;
218219

220+
/**
221+
* Marks the the account with the default zone-id.
222+
*
223+
* @param accountName
224+
* @param domainId
225+
* @param zoneId
226+
* @return The new account object
227+
* @throws ,
228+
*/
229+
Account markDefaultZone(String accountName, long domainId, long defaultZoneId);
230+
219231
boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd);
220232

221233
NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd);

api/src/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class EventTypes {
7272
public static final String EVENT_ACCOUNT_DISABLE = "ACCOUNT.DISABLE";
7373
public static final String EVENT_ACCOUNT_CREATE = "ACCOUNT.CREATE";
7474
public static final String EVENT_ACCOUNT_DELETE = "ACCOUNT.DELETE";
75+
public static final String EVENT_ACCOUNT_MARK_DEFAULT_ZONE = "ACCOUNT.MARK.DEFAULT.ZONE";
7576

7677
// UserVO Events
7778
public static final String EVENT_USER_LOGIN = "USER.LOGIN";

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ public enum State {
5555
public Date getRemoved();
5656

5757
public String getNetworkDomain();
58+
59+
public Long getDefaultZoneId();
5860
}

core/src/com/cloud/user/AccountVO.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class AccountVO implements Account, Identity {
5959

6060
@Column(name="uuid")
6161
private String uuid;
62+
63+
@Column(name="default_zone_id")
64+
private Long defaultZoneId = null;
6265

6366
public AccountVO() {
6467
this.uuid = UUID.randomUUID().toString();
@@ -117,6 +120,15 @@ public long getDomainId() {
117120
public void setDomainId(long domainId) {
118121
this.domainId = domainId;
119122
}
123+
124+
@Override
125+
public Long getDefaultZoneId() {
126+
return defaultZoneId;
127+
}
128+
129+
public void setDefaultZoneId(Long defaultZoneId) {
130+
this.defaultZoneId = defaultZoneId;
131+
}
120132

121133
@Override
122134
public State getState() {

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,12 +1391,10 @@ public List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDe
13911391
}
13921392
}
13931393

1394-
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
1395-
if (userVm.getHypervisorType() != null) {
1396-
userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
1397-
}
1394+
if (userVm.getHypervisorType() != null) {
1395+
userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
13981396
}
1399-
1397+
14001398
if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) {
14011399
// Template Info
14021400
VMTemplateVO template = templates.get(userVm.getTemplateId());
@@ -2973,11 +2971,8 @@ public UserVmData newUserVmData(UserVm userVm) {
29732971

29742972
userVmData.setDomainId(userVm.getDomainId());
29752973

2976-
Account caller = UserContext.current().getCaller();
2977-
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
2978-
if (userVm.getHypervisorType() != null) {
2979-
userVmData.setHypervisor(userVm.getHypervisorType().toString());
2980-
}
2974+
if (userVm.getHypervisorType() != null) {
2975+
userVmData.setHypervisor(userVm.getHypervisorType().toString());
29812976
}
29822977

29832978
if (userVm.getPassword() != null) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public enum Config {
219219
ElasticLoadBalancerVmNumVcpu("Advanced", ManagementServer.class, Integer.class, "network.loadbalancer.basiczone.elb.vm.vcpu.num", "1", "Number of VCPU for the elastic load balancer vm", null),
220220
ElasticLoadBalancerVmGcInterval("Advanced", ManagementServer.class, Integer.class, "network.loadbalancer.basiczone.elb.gc.interval.minutes", "30", "Garbage collection interval to destroy unused ELB vms in minutes. Minimum of 5", null),
221221
SortKeyAlgorithm("Advanced", ManagementServer.class, Boolean.class, "sortkey.algorithm", "false", "Sort algorithm for those who use sort key(template, disk offering, service offering, network offering), true means ascending sort while false means descending sort", null),
222+
EnableEC2API("Advanced", ManagementServer.class, Boolean.class, "enable.ec2.api", "false", "enable EC2 API on CloudStack", null),
223+
EnableS3API("Advanced", ManagementServer.class, Boolean.class, "enable.s3.api", "false", "enable Amazon S3 API on CloudStack", null),
222224

223225
// Ovm
224226
OvmPublicNetwork("Hidden", ManagementServer.class, String.class, "ovm.public.network.device", null, "Specify the public bridge on host for public network", null),

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
import com.cloud.storage.swift.SwiftManager;
139139
import com.cloud.test.IPRangeConfig;
140140
import com.cloud.user.Account;
141-
import com.cloud.user.AccountManager;
142141
import com.cloud.user.AccountVO;
142+
import com.cloud.user.AccountManager;
143143
import com.cloud.user.ResourceLimitService;
144144
import com.cloud.user.User;
145145
import com.cloud.user.UserContext;
@@ -3574,6 +3574,34 @@ public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) {
35743574
}
35753575
}
35763576

3577+
@Override
3578+
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the default zone", async=true)
3579+
public AccountVO markDefaultZone(String accountName, long domainId, long defaultZoneId) {
3580+
3581+
// Check if the account exists
3582+
Account account = _accountDao.findEnabledAccount(accountName, domainId);
3583+
if (account == null) {
3584+
s_logger.error("Unable to find account by name: " + accountName + " in domain " + domainId);
3585+
throw new InvalidParameterValueException("Account by name: " + accountName + " doesn't exist in domain " + domainId);
3586+
}
3587+
3588+
// Don't allow modification of system account
3589+
if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
3590+
throw new InvalidParameterValueException("Can not modify system account");
3591+
}
3592+
3593+
AccountVO acctForUpdate = _accountDao.findById(account.getId());
3594+
3595+
acctForUpdate.setDefaultZoneId(defaultZoneId);
3596+
3597+
if (_accountDao.update(account.getId(), acctForUpdate)) {
3598+
UserContext.current().setEventDetails("Default zone id= " + defaultZoneId);
3599+
return _accountDao.findById(account.getId());
3600+
} else {
3601+
return null;
3602+
}
3603+
}
3604+
35773605
// Note: This method will be used for entity name validations in the coming
35783606
// releases (place holder for now)
35793607
private void validateEntityName(String str) {

0 commit comments

Comments
 (0)