|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.cloudstack.api.command.user.bootgroup; |
| 19 | + |
| 20 | +import javax.inject.Inject; |
| 21 | + |
| 22 | +import org.apache.cloudstack.acl.RoleType; |
| 23 | +import org.apache.cloudstack.api.APICommand; |
| 24 | +import org.apache.cloudstack.api.ApiCommandResourceType; |
| 25 | +import org.apache.cloudstack.api.ApiConstants; |
| 26 | +import org.apache.cloudstack.api.ApiErrorCode; |
| 27 | +import org.apache.cloudstack.api.BaseCmd; |
| 28 | +import org.apache.cloudstack.api.Parameter; |
| 29 | +import org.apache.cloudstack.api.ServerApiException; |
| 30 | +import org.apache.cloudstack.api.command.user.UserCmd; |
| 31 | +import org.apache.cloudstack.api.response.DomainResponse; |
| 32 | +import org.apache.cloudstack.api.response.InstanceBootGroupResponse; |
| 33 | +import org.apache.cloudstack.api.response.ProjectResponse; |
| 34 | +import org.apache.cloudstack.context.CallContext; |
| 35 | +import org.apache.cloudstack.vm.bootgroup.InstanceBootGroup; |
| 36 | +import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService; |
| 37 | + |
| 38 | +@APICommand(name = "createInstanceBootGroup", |
| 39 | + description = "Creates an Instance Boot Group", |
| 40 | + since = "24.0", |
| 41 | + responseObject = InstanceBootGroupResponse.class, |
| 42 | + entityType = {InstanceBootGroup.class}, |
| 43 | + requestHasSensitiveInfo = false, |
| 44 | + responseHasSensitiveInfo = false, |
| 45 | + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) |
| 46 | +public class CreateInstanceBootGroupCmd extends BaseCmd implements UserCmd { |
| 47 | + |
| 48 | + @Inject |
| 49 | + InstanceBootGroupService instanceBootGroupService; |
| 50 | + |
| 51 | + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "The name of the Instance Boot Group") |
| 52 | + private String name; |
| 53 | + |
| 54 | + @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the Instance Boot Group") |
| 55 | + private String description; |
| 56 | + |
| 57 | + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "The account of the Instance Boot Group. Must be used with domainid") |
| 58 | + private String accountName; |
| 59 | + |
| 60 | + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "The domain ID of the account owning the Instance Boot Group") |
| 61 | + private Long domainId; |
| 62 | + |
| 63 | + @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "The project of the Instance Boot Group") |
| 64 | + private Long projectId; |
| 65 | + |
| 66 | + @Parameter(name = ApiConstants.READINESS_ATTEMPT_TIMEOUT_SECONDS, type = CommandType.LONG, |
| 67 | + description = "Per-boot-group override of the global timeout (seconds) for each readiness retry attempt") |
| 68 | + private Long readinessAttemptTimeoutSeconds; |
| 69 | + |
| 70 | + @Parameter(name = ApiConstants.READINESS_MAX_RETRY_ATTEMPTS, type = CommandType.LONG, |
| 71 | + description = "Per-boot-group override of the global maximum number of readiness retry attempts") |
| 72 | + private Long readinessMaxRetryAttempts; |
| 73 | + |
| 74 | + @Parameter(name = ApiConstants.READINESS_REBOOT_ON_RETRY, type = CommandType.BOOLEAN, |
| 75 | + description = "Per-boot-group override of whether an instance is rebooted between readiness retry attempts") |
| 76 | + private Boolean readinessRebootOnRetry; |
| 77 | + |
| 78 | + @Parameter(name = ApiConstants.READINESS_INITIAL_DELAY_SECONDS, type = CommandType.LONG, |
| 79 | + description = "Per-boot-group override of the global delay (seconds) after starting or rebooting an instance before its first readiness check of that attempt") |
| 80 | + private Long readinessInitialDelaySeconds; |
| 81 | + |
| 82 | + public String getName() { |
| 83 | + return name; |
| 84 | + } |
| 85 | + |
| 86 | + public String getDescription() { |
| 87 | + return description; |
| 88 | + } |
| 89 | + |
| 90 | + public String getAccountName() { |
| 91 | + return accountName; |
| 92 | + } |
| 93 | + |
| 94 | + public Long getDomainId() { |
| 95 | + return domainId; |
| 96 | + } |
| 97 | + |
| 98 | + public Long getProjectId() { |
| 99 | + return projectId; |
| 100 | + } |
| 101 | + |
| 102 | + public Long getReadinessAttemptTimeoutSeconds() { |
| 103 | + return readinessAttemptTimeoutSeconds; |
| 104 | + } |
| 105 | + |
| 106 | + public Long getReadinessMaxRetryAttempts() { |
| 107 | + return readinessMaxRetryAttempts; |
| 108 | + } |
| 109 | + |
| 110 | + public Boolean getReadinessRebootOnRetry() { |
| 111 | + return readinessRebootOnRetry; |
| 112 | + } |
| 113 | + |
| 114 | + public Long getReadinessInitialDelaySeconds() { |
| 115 | + return readinessInitialDelaySeconds; |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public long getEntityOwnerId() { |
| 120 | + Long accountId = _accountService.finalizeAccountId(accountName, domainId, projectId, true); |
| 121 | + if (accountId == null) { |
| 122 | + return CallContext.current().getCallingAccount().getId(); |
| 123 | + } |
| 124 | + return accountId; |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public ApiCommandResourceType getApiResourceType() { |
| 129 | + return ApiCommandResourceType.InstanceBootGroup; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public void execute() { |
| 134 | + InstanceBootGroup result = instanceBootGroupService.createInstanceBootGroup(this); |
| 135 | + if (result == null) { |
| 136 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create instance boot group"); |
| 137 | + } |
| 138 | + InstanceBootGroupResponse response = instanceBootGroupService.createInstanceBootGroupResponse(result.getId()); |
| 139 | + response.setResponseName(getCommandName()); |
| 140 | + setResponseObject(response); |
| 141 | + } |
| 142 | +} |
0 commit comments