refactor getUploadParamsForIso (#7813)

Co-authored-by: Henrique Sato <henrique.sato@scclouds.com.br>
This commit is contained in:
sato03 2023-08-31 18:11:00 -03:00 committed by GitHub
parent 78411fd405
commit 5917fed773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 24 deletions

View File

@ -31,18 +31,18 @@ public abstract class AbstractGetUploadParamsCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AbstractGetUploadParamsCmd.class.getName());
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the volume/template")
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the volume/template/iso")
private String name;
@Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, required = true, description = "the format for the volume/template. Possible values include QCOW2, OVA, "
@Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, required = true, description = "the format for the volume/template/iso. Possible values include QCOW2, OVA, "
+ "and VHD.")
private String format;
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the ID of the zone the volume/template is "
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the ID of the zone the volume/template/iso is "
+ "to be hosted on")
private Long zoneId;
@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING, description = "the checksum value of this volume/template " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING, description = "the checksum value of this volume/template/iso " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
private String checksum;
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional accountName. Must be used with domainId.")
@ -52,7 +52,7 @@ public abstract class AbstractGetUploadParamsCmd extends BaseCmd {
+ "domainId must also be used.")
private Long domainId;
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Upload volume/template for the project")
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Upload volume/template/iso for the project")
private Long projectId;
public String getName() {

View File

@ -28,7 +28,6 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.GuestOSResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext;
import com.cloud.exception.ConcurrentOperationException;
@ -37,15 +36,13 @@ import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
@APICommand(name = GetUploadParamsForIsoCmd.APINAME,
@APICommand(name = "getUploadParamsForIso",
description = "upload an existing ISO into the CloudStack cloud.",
responseObject = GetUploadParamsResponse.class, since = "4.13",
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User},
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
public static final String APINAME = "getUploadParamsForIso";
private static final String s_name = "postuploadisoresponse";
/////////////////////////////////////////////////////
@ -73,19 +70,12 @@ public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
@Parameter(name = ApiConstants.IS_EXTRACTABLE, type = BaseCmd.CommandType.BOOLEAN, description = "true if the ISO or its derivatives are extractable; default is false")
private Boolean extractable;
@Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, required = true, description = "the name of the ISO")
private String isoName;
@Parameter(name = ApiConstants.OS_TYPE_ID,
type = BaseCmd.CommandType.UUID,
entityType = GuestOSResponse.class,
description = "the ID of the OS type that best represents the OS of this ISO. If the ISO is bootable this parameter needs to be passed")
private Long osTypeId;
@Parameter(name=ApiConstants.ZONE_ID, type= BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
required=true, description="the ID of the zone you wish to register the ISO to.")
protected Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -110,17 +100,10 @@ public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
return extractable;
}
public String getIsoName() {
return isoName;
}
public Long getOsTypeId() {
return osTypeId;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@ -134,7 +117,7 @@ public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (ResourceAllocationException | MalformedURLException e) {
s_logger.error("Exception while registering template", e);
s_logger.error("Exception while registering ISO", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Exception while registering ISO: " + e.getMessage());
}
}