|
| 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 | + |
0 commit comments