From 498711ab90a8d5bc2a59fdf4c981399257c521a3 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Wed, 13 Mar 2019 09:27:25 -0300 Subject: [PATCH 1/6] Add local ISO upload via UI --- .../cloud/template/TemplateApiService.java | 5 +- .../user/iso/GetUploadParamsForIsoCmd.java | 158 ++++++++++++++++ .../manager/BareMetalTemplateAdapter.java | 6 + .../cloud/server/ManagementServerImpl.java | 2 + .../template/HypervisorTemplateAdapter.java | 10 + .../com/cloud/template/TemplateAdapter.java | 25 +-- .../cloud/template/TemplateAdapterBase.java | 54 ++++-- .../cloud/template/TemplateManagerImpl.java | 29 ++- ui/l10n/en.js | 1 + ui/l10n/es.js | 1 + ui/scripts/templates.js | 174 ++++++++++++++++++ 11 files changed, 435 insertions(+), 30 deletions(-) create mode 100644 api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java diff --git a/api/src/main/java/com/cloud/template/TemplateApiService.java b/api/src/main/java/com/cloud/template/TemplateApiService.java index 7348547cee05..b62628560ae4 100644 --- a/api/src/main/java/com/cloud/template/TemplateApiService.java +++ b/api/src/main/java/com/cloud/template/TemplateApiService.java @@ -24,6 +24,7 @@ import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd; import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd; import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd; import org.apache.cloudstack.api.command.user.template.CopyTemplateCmd; @@ -45,10 +46,12 @@ public interface TemplateApiService { VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException; - public GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException; + GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException; VirtualMachineTemplate registerIso(RegisterIsoCmd cmd) throws IllegalArgumentException, ResourceAllocationException; + GetUploadParamsResponse registerIsoForPostUpload(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException, MalformedURLException; + VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException; VirtualMachineTemplate prepareTemplate(long templateId, long zoneId, Long storageId); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java new file mode 100644 index 000000000000..6bdf6a2f9cf3 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java @@ -0,0 +1,158 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.iso; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.AbstractGetUploadParamsCmd; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +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 java.net.MalformedURLException; + +@APICommand(name = GetUploadParamsForIsoCmd.APINAME, + description = "upload an existing ISO into the CloudStack cloud.", + responseObject = GetUploadParamsResponse.class, since = "4.11.2", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd { + + public static final String APINAME = "getUploadParamsForIso"; + + private static final String s_name = "postuploadisoresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.BOOTABLE, type = BaseCmd.CommandType.BOOLEAN, description = "true if this ISO is bootable. If not passed explicitly its assumed to be true") + private Boolean bootable; + + @Parameter(name = ApiConstants.DISPLAY_TEXT, + type = BaseCmd.CommandType.STRING, + required = true, + description = "the display text of the ISO. This is usually used for display purposes.", + length = 4096) + private String displayText; + + @Parameter(name = ApiConstants.IS_FEATURED, type = BaseCmd.CommandType.BOOLEAN, description = "true if you want this ISO to be featured") + private Boolean featured; + + @Parameter(name = ApiConstants.IS_PUBLIC, + type = BaseCmd.CommandType.BOOLEAN, + description = "true if you want to register the ISO to be publicly available to all users, false otherwise.") + private Boolean publicIso; + + @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 /////////////////////// + ///////////////////////////////////////////////////// + + public Boolean isBootable() { + return bootable; + } + + public String getDisplayText() { + return displayText; + } + + public Boolean isFeatured() { + return featured; + } + + public Boolean isPublic() { + return publicIso; + } + + public Boolean isExtractable() { + return extractable; + } + + public String getIsoName() { + return isoName; + } + + public Long getOsTypeId() { + return osTypeId; + } + + public Long getZoneId() { + return zoneId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + validateRequest(); + try { + GetUploadParamsResponse response = _templateService.registerIsoForPostUpload(this); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (ResourceAllocationException | MalformedURLException e) { + s_logger.error("Exception while registering template", e); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Exception while registering ISO: " + e.getMessage()); + } + } + + private void validateRequest() { + if (getZoneId() <= 0) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid zoneid"); + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Long accountId = _accountService.finalyzeAccountId(getAccountName(), getDomainId(), getProjectId(), true); + if (accountId == null) { + return CallContext.current().getCallingAccount().getId(); + } + return accountId; + } +} \ No newline at end of file diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java index d2d0029701a6..8265f951f8a8 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java @@ -40,6 +40,7 @@ import com.cloud.utils.db.DB; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd; import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand; @@ -72,6 +73,11 @@ public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationExce throw new CloudRuntimeException("Baremetal doesn't support ISO template"); } + @Override + public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException { + throw new CloudRuntimeException("Baremetal doesn't support ISO template"); + } + private void templateCreateUsage(VMTemplateVO template, long dcId) { if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) { UsageEventVO usageEvent = diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index b211cab27a23..7e36d8697f4a 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -338,6 +338,7 @@ import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; import org.apache.cloudstack.api.command.user.iso.DetachIsoCmd; import org.apache.cloudstack.api.command.user.iso.ExtractIsoCmd; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.iso.ListIsoPermissionsCmd; import org.apache.cloudstack.api.command.user.iso.ListIsosCmd; import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd; @@ -3070,6 +3071,7 @@ public List> getCommands() { cmdList.add(DeleteManagementNetworkIpRangeCmd.class); cmdList.add(UploadTemplateDirectDownloadCertificate.class); cmdList.add(ListMgmtsCmd.class); + cmdList.add(GetUploadParamsForIsoCmd.class); // Out-of-band management APIs for admins cmdList.add(EnableOutOfBandManagementForHostCmd.class); diff --git a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java index 8aa21661675f..e2db31a16c90 100644 --- a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java @@ -35,6 +35,7 @@ import com.cloud.utils.db.TransactionStatus; import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer; import org.apache.cloudstack.agent.directdownload.CheckUrlCommand; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.template.GetUploadParamsForTemplateCmd; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; @@ -166,6 +167,15 @@ public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationExce return profile; } + @Override + public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException { + TemplateProfile profile = super.prepare(cmd); + + // Check that the resource limit for secondary storage won't be exceeded + _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()), ResourceType.secondary_storage); + return profile; + } + @Override public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException { TemplateProfile profile = super.prepare(cmd); diff --git a/server/src/main/java/com/cloud/template/TemplateAdapter.java b/server/src/main/java/com/cloud/template/TemplateAdapter.java index 595de66ed17b..c048ceaf1fc2 100644 --- a/server/src/main/java/com/cloud/template/TemplateAdapter.java +++ b/server/src/main/java/com/cloud/template/TemplateAdapter.java @@ -20,6 +20,7 @@ import java.util.Map; import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd; import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd; import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd; @@ -51,29 +52,31 @@ public String getName() { } } - public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException; + TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException; - public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException; + TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException; - public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException; + TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException; - public VMTemplateVO create(TemplateProfile profile); + TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException; - public List createTemplateForPostUpload(TemplateProfile profile); + VMTemplateVO create(TemplateProfile profile); - public TemplateProfile prepareDelete(DeleteTemplateCmd cmd); + List createTemplateForPostUpload(TemplateProfile profile); - public TemplateProfile prepareDelete(DeleteIsoCmd cmd); + TemplateProfile prepareDelete(DeleteTemplateCmd cmd); - public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd cmd); + TemplateProfile prepareDelete(DeleteIsoCmd cmd); - public boolean delete(TemplateProfile profile); + TemplateProfile prepareExtractTemplate(ExtractTemplateCmd cmd); - public TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, String url, + boolean delete(TemplateProfile profile); + + TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured, Boolean isExtractable, String format, Long guestOSId, List zoneId, HypervisorType hypervisorType, String accountName, Long domainId, String chksum, Boolean bootable, Map details, boolean directDownload) throws ResourceAllocationException; - public TemplateProfile prepare(boolean isIso, long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, String url, + TemplateProfile prepare(boolean isIso, long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured, Boolean isExtractable, String format, Long guestOSId, List zoneId, HypervisorType hypervisorType, String chksum, Boolean bootable, String templateTag, Account templateOwner, Map details, Boolean sshKeyEnabled, String imageStoreUuid, Boolean isDynamicallyScalable, TemplateType templateType, boolean directDownload) throws ResourceAllocationException; diff --git a/server/src/main/java/com/cloud/template/TemplateAdapterBase.java b/server/src/main/java/com/cloud/template/TemplateAdapterBase.java index dc4074c957f9..5128476b201e 100644 --- a/server/src/main/java/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/main/java/com/cloud/template/TemplateAdapterBase.java @@ -23,6 +23,7 @@ import javax.inject.Inject; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.template.GetUploadParamsForTemplateCmd; import org.apache.commons.collections.CollectionUtils; import org.apache.log4j.Logger; @@ -284,17 +285,26 @@ public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocatio } - @Override - public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException { + /** + * Prepare upload parameters internal method for templates and ISOs local upload + */ + private TemplateProfile prepareUploadParamsInternal(boolean isIso, long userId, String name, String displayText, + Integer bits, Boolean passwordEnabled, Boolean requiresHVM, + String url, Boolean isPublic, Boolean featured, + Boolean isExtractable, String format, Long guestOSId, + Long zoneId, HypervisorType hypervisorType, String chksum, + Boolean bootable, String templateTag, long templateOwnerId, + Map details, Boolean sshkeyEnabled, String imageStoreUuid, + Boolean isDynamicallyScalable, Boolean isRoutingType, + boolean directDownload) throws ResourceAllocationException { //check if the caller can operate with the template owner Account caller = CallContext.current().getCallingAccount(); - Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); + Account owner = _accountMgr.getAccount(templateOwnerId); _accountMgr.checkAccess(caller, null, true, owner); - boolean isRouting = (cmd.isRoutingType() == null) ? false : cmd.isRoutingType(); + boolean isRouting = (isRoutingType == null) ? false : isRoutingType; List zoneList = null; - Long zoneId = cmd.getZoneId(); // ignore passed zoneId if we are using region wide image store List stores = _imgStoreDao.findRegionImageStores(); if (!(stores != null && stores.size() > 0)) { @@ -302,17 +312,35 @@ public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws Resourc zoneList.add(zoneId); } - HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor()); - if(hypervisorType == HypervisorType.None) { - throw new InvalidParameterValueException("Hypervisor Type: " + cmd.getHypervisor() + " is invalid. Supported Hypervisor types are " - + EnumUtils.listValues(HypervisorType.values()).replace("None, ", "")); + if(!isIso && hypervisorType == HypervisorType.None) { + throw new InvalidParameterValueException("Hypervisor Type: " + hypervisorType + " is invalid. Supported Hypervisor types are " + + EnumUtils.listValues(HypervisorType.values()).replace("None, ", "")); } - return prepare(false, CallContext.current().getCallingUserId(), cmd.getName(), cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), - cmd.getRequiresHvm(), null, cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), zoneList, - hypervisorType, cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, - cmd.isDynamicallyScalable(), isRouting ? TemplateType.ROUTING : TemplateType.USER, false); + return prepare(isIso, userId, name, displayText, bits, passwordEnabled, + requiresHVM, url, isPublic, featured, isExtractable, format, guestOSId, zoneList, + hypervisorType, chksum, bootable, templateTag, owner, details, sshkeyEnabled, imageStoreUuid, + isDynamicallyScalable, isRouting ? TemplateType.ROUTING : TemplateType.USER, directDownload); + } + @Override + public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException { + return prepareUploadParamsInternal(false, CallContext.current().getCallingUserId(), cmd.getName(), + cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), null, + cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), + cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(), true, + cmd.getTemplateTag(), cmd.getEntityOwnerId(), cmd.getDetails(), cmd.isSshKeyEnabled(), + null, cmd.isDynamicallyScalable(), cmd.isRoutingType(), false); + } + + @Override + public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException { + return prepareUploadParamsInternal(true, CallContext.current().getCallingUserId(), cmd.getName(), + cmd.getDisplayText(), 64, false, true, null, + cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), ImageFormat.ISO.toString(), cmd.getOsTypeId(), + cmd.getZoneId(), HypervisorType.None, null, cmd.isBootable(), + null, cmd.getEntityOwnerId(), null, false, + null, false, false, false); } @Override diff --git a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java index df3b59b5ff73..9cba758ec2af 100755 --- a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java @@ -43,6 +43,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.template.GetUploadParamsForTemplateCmd; import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand; @@ -349,11 +350,14 @@ public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws U } } - @Override - @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating post upload template") - public GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException { - TemplateAdapter adapter = getAdapter(HypervisorType.getType(cmd.getHypervisor())); - TemplateProfile profile = adapter.prepare(cmd); + /** + * Internal register template or ISO method - post local upload + * @param adapter + * @param profile + */ + private GetUploadParamsResponse registerPostUploadInternal(TemplateAdapter adapter, + TemplateProfile profile) throws MalformedURLException { + List payload = adapter.createTemplateForPostUpload(profile); if(CollectionUtils.isNotEmpty(payload)) { @@ -403,6 +407,21 @@ public GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForT } } + @Override + @ActionEvent(eventType = EventTypes.EVENT_ISO_CREATE, eventDescription = "creating post upload iso") + public GetUploadParamsResponse registerIsoForPostUpload(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException, MalformedURLException { + TemplateAdapter adapter = getAdapter(HypervisorType.None); + TemplateProfile profile = adapter.prepare(cmd); + return registerPostUploadInternal(adapter, profile); + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating post upload template") + public GetUploadParamsResponse registerTemplateForPostUpload(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException { + TemplateAdapter adapter = getAdapter(HypervisorType.getType(cmd.getHypervisor())); + TemplateProfile profile = adapter.prepare(cmd); + return registerPostUploadInternal(adapter, profile); + } @Override public DataStore getImageStore(String storeUuid, Long zoneId) { diff --git a/ui/l10n/en.js b/ui/l10n/en.js index eb7b82250891..805bf42fd02d 100644 --- a/ui/l10n/en.js +++ b/ui/l10n/en.js @@ -1721,6 +1721,7 @@ var dictionary = { "label.upgrade.router.newer.template":"Upgrade Router to Use Newer Template", "label.upload":"Upload", "label.upload.from.local":"Upload from Local", +"label.upload.iso.from.local":"Upload ISO from Local", "label.upload.template.from.local":"Upload Template from Local", "label.upload.volume":"Upload volume", "label.upload.volume.from.local":"Upload Volume from Local", diff --git a/ui/l10n/es.js b/ui/l10n/es.js index 285df3d232f3..610c62eeeea7 100644 --- a/ui/l10n/es.js +++ b/ui/l10n/es.js @@ -1666,6 +1666,7 @@ var dictionary = { "label.upgrade.router.newer.template": "Actualizar Router para usar una Plantilla más Nueva", "label.upload": "Subir", "label.upload.from.local": "Subir desde Local", + "label.upload.iso.from.local":"Subir ISO desde Local", "label.upload.template.from.local": "Subir Plantilla desde Local", "label.upload.volume": "Subir volumen", "label.upload.volume.from.local": "Subir un Volumen desde Local", diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js index 96660fac6804..9a76e227039e 100755 --- a/ui/scripts/templates.js +++ b/ui/scripts/templates.js @@ -2323,6 +2323,180 @@ }); }, + notification: { + poll: function(args) { + args.complete(); + } + } + }, + uploadISOFromLocal: { + isHeader: true, + label: 'label.upload.from.local', + messages: { + notification: function(args) { + return 'label.upload.iso.from.local'; + } + }, + createForm: { + title: 'label.upload.iso.from.local', + preFilter: cloudStack.preFilter.createTemplate, + fileUpload: { + getURL: function(args) { + args.data = args.formData; + + var data = { + name: args.data.name, + displayText: args.data.description, + zoneid: args.data.zone, + format: "ISO", + isextractable: (args.data.isExtractable == "on"), + bootable: (args.data.isBootable == "on"), + ispublic: (args.data.isPublic == "on"), + isfeatured: (args.data.isFeatured == "on") + }; + + if (args.$form.find('.form-item[rel=osTypeId]').is(':visible')) { + $.extend(data, { + osTypeId: args.data.osTypeId, + }); + } + + $.ajax({ + url: createURL('getUploadParamsForIso'), + data: data, + async: false, + success: function(json) { + var uploadparams = json.postuploadisoresponse.getuploadparams; + var templateId = uploadparams.id; + + args.response.success({ + url: uploadparams.postURL, + ajaxPost: true, + data: { + 'X-signature': uploadparams.signature, + 'X-expires': uploadparams.expires, + 'X-metadata': uploadparams.metadata + } + }); + } + }); + }, + postUpload: function(args) { + if(args.error) { + args.response.error(args.errorMsg); + } else { + cloudStack.dialog.notice({ + message: "This ISO file has been uploaded. Please check its status at Templates menu > " + args.data.name + " > Zones tab > click a zone > Status field and Ready field." + }); + args.response.success(); + } + } + }, + fields: { + templateFileUpload: { + label: 'label.local.file', + isFileUpload: true, + validation: { + required: true + } + }, + name: { + label: 'label.name', + docID: 'helpRegisterISOName', + validation: { + required: true + } + }, + description: { + label: 'label.description', + docID: 'helpRegisterISODescription', + validation: { + required: true + } + }, + + zone: { + label: 'label.zone', + docID: 'helpRegisterISOZone', + select: function(args) { + $.ajax({ + url: createURL("listZones&available=true"), + dataType: "json", + async: true, + success: function(json) { + var zoneObjs = json.listzonesresponse.zone; + args.response.success({ + descriptionField: 'name', + data: zoneObjs + }); + } + }); + } + }, + + isBootable: { + label: "label.bootable", + docID: 'helpRegisterISOBootable', + isBoolean: true, + isChecked: true + }, + + osTypeId: { + label: 'label.os.type', + docID: 'helpRegisterISOOSType', + dependsOn: 'isBootable', + isHidden: false, + validation: { + required: true + }, + select: function(args) { + $.ajax({ + url: createURL("listOsTypes"), + dataType: "json", + async: true, + success: function(json) { + var ostypeObjs = json.listostypesresponse.ostype; + var items = []; + $(ostypeObjs).each(function() { + items.push({ + id: this.id, + description: this.description + }); + }); + args.response.success({ + data: items + }); + } + }); + } + }, + + isExtractable: { + label: "label.extractable", + docID: 'helpRegisterISOExtractable', + isBoolean: true + }, + + isPublic: { + label: "label.public", + docID: 'helpRegisterISOPublic', + isBoolean: true, + isHidden: true + }, + + isFeatured: { + label: "label.featured", + docID: 'helpRegisterISOFeatured', + isBoolean: true, + isHidden: true + } + } + }, + + action: function(args) { + return; + }, + notification: { poll: function(args) { args.complete(); From dcb9875d9d04c93878e907fa61be7df7bd9e3a80 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Mon, 1 Apr 2019 22:02:49 -0300 Subject: [PATCH 2/6] Fix API since value --- .../api/command/user/iso/GetUploadParamsForIsoCmd.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java index 6bdf6a2f9cf3..92e3b979885b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java @@ -37,7 +37,7 @@ @APICommand(name = GetUploadParamsForIsoCmd.APINAME, description = "upload an existing ISO into the CloudStack cloud.", - responseObject = GetUploadParamsResponse.class, since = "4.11.2", + responseObject = GetUploadParamsResponse.class, since = "4.13", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd { From 1ef1d818a857b504198aceb8a548302d9b362cc4 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Wed, 3 Apr 2019 16:41:01 -0300 Subject: [PATCH 3/6] Refactor upload parameters --- .../upload/params/IsoUploadParams.java | 33 +++ .../upload/params/TemplateUploadParams.java | 38 +++ .../storage/upload/params/UploadParams.java | 49 ++++ .../upload/params/UploadParamsBase.java | 240 ++++++++++++++++++ .../cloud/template/TemplateAdapterBase.java | 52 ++-- 5 files changed, 384 insertions(+), 28 deletions(-) create mode 100644 server/src/main/java/com/cloud/storage/upload/params/IsoUploadParams.java create mode 100644 server/src/main/java/com/cloud/storage/upload/params/TemplateUploadParams.java create mode 100644 server/src/main/java/com/cloud/storage/upload/params/UploadParams.java create mode 100644 server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java diff --git a/server/src/main/java/com/cloud/storage/upload/params/IsoUploadParams.java b/server/src/main/java/com/cloud/storage/upload/params/IsoUploadParams.java new file mode 100644 index 000000000000..7c2b5799e962 --- /dev/null +++ b/server/src/main/java/com/cloud/storage/upload/params/IsoUploadParams.java @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.storage.upload.params; + +import com.cloud.hypervisor.Hypervisor; +import com.cloud.storage.Storage; + +public class IsoUploadParams extends UploadParamsBase { + + public IsoUploadParams(long userId, String name, String displayText, Boolean isPublic, Boolean isFeatured, + Boolean isExtractable, Long osTypeId, Long zoneId, Boolean bootable, long ownerId) { + super(userId, name, displayText, isPublic, isFeatured, isExtractable, osTypeId, zoneId, bootable, ownerId); + setIso(true); + setBits(64); + setFormat(Storage.ImageFormat.ISO.toString()); + setHypervisorType(Hypervisor.HypervisorType.None); + setRequiresHVM(true); + } +} diff --git a/server/src/main/java/com/cloud/storage/upload/params/TemplateUploadParams.java b/server/src/main/java/com/cloud/storage/upload/params/TemplateUploadParams.java new file mode 100644 index 000000000000..9dede2ee5a3e --- /dev/null +++ b/server/src/main/java/com/cloud/storage/upload/params/TemplateUploadParams.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.storage.upload.params; + +import com.cloud.hypervisor.Hypervisor; + +import java.util.Map; + +public class TemplateUploadParams extends UploadParamsBase { + + public TemplateUploadParams(long userId, String name, String displayText, + Integer bits, Boolean passwordEnabled, Boolean requiresHVM, + Boolean isPublic, Boolean featured, + Boolean isExtractable, String format, Long guestOSId, + Long zoneId, Hypervisor.HypervisorType hypervisorType, String chksum, + String templateTag, long templateOwnerId, + Map details, Boolean sshkeyEnabled, + Boolean isDynamicallyScalable, Boolean isRoutingType) { + super(userId, name, displayText, bits, passwordEnabled, requiresHVM, isPublic, featured, isExtractable, + format, guestOSId, zoneId, hypervisorType, chksum, templateTag, templateOwnerId, details, + sshkeyEnabled, isDynamicallyScalable, isRoutingType); + setBootable(true); + } +} diff --git a/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java b/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java new file mode 100644 index 000000000000..9d3ae2d07e01 --- /dev/null +++ b/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.storage.upload.params; + +import com.cloud.hypervisor.Hypervisor; + +import java.util.Map; + +public interface UploadParams { + boolean isIso(); + long getUserId(); + String getName(); + String getDisplayText(); + Integer getBits(); + Boolean isPasswordEnabled(); + Boolean requiresHVM(); + String getUrl(); + Boolean isPublic(); + Boolean isFeatured(); + Boolean isExtractable(); + String getFormat(); + Long getGuestOSId(); + Long getZoneId(); + Hypervisor.HypervisorType getHypervisorType(); + String getChecksum(); + Boolean isBootable(); + String getTemplateTag(); + long getTemplateOwnerId(); + Map getDetails(); + Boolean isSshKeyEnabled(); + String getImageStoreUuid(); + Boolean isDynamicallyScalable(); + Boolean isRoutingType(); + boolean isDirectDownload(); +} diff --git a/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java b/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java new file mode 100644 index 000000000000..6b9a11206092 --- /dev/null +++ b/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java @@ -0,0 +1,240 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.storage.upload.params; + +import com.cloud.hypervisor.Hypervisor; + +import java.util.Map; + +public abstract class UploadParamsBase implements UploadParams { + + private boolean isIso; + private long userId; + private String name; + private String displayText; + private Integer bits; + private Boolean passwordEnabled; + private Boolean requiresHVM; + private Boolean isPublic; + private Boolean featured; + private Boolean isExtractable; + private String format; + private Long guestOSId; + private Long zoneId; + private Hypervisor.HypervisorType hypervisorType; + private String checksum; + private Boolean bootable; + private String templateTag; + private long templateOwnerId; + private Map details; + private Boolean sshkeyEnabled; + private Boolean isDynamicallyScalable; + private Boolean isRoutingType; + + UploadParamsBase(long userId, String name, String displayText, + Integer bits, Boolean passwordEnabled, Boolean requiresHVM, + Boolean isPublic, Boolean featured, + Boolean isExtractable, String format, Long guestOSId, + Long zoneId, Hypervisor.HypervisorType hypervisorType, String checksum, + String templateTag, long templateOwnerId, + Map details, Boolean sshkeyEnabled, + Boolean isDynamicallyScalable, Boolean isRoutingType) { + this.userId = userId; + this.name = name; + this.displayText = displayText; + this.bits = bits; + this.passwordEnabled = passwordEnabled; + this.requiresHVM = requiresHVM; + this.isPublic = isPublic; + this.featured = featured; + this.isExtractable = isExtractable; + this.format = format; + this.guestOSId = guestOSId; + this.zoneId = zoneId; + this.hypervisorType = hypervisorType; + this.checksum = checksum; + this.templateTag = templateTag; + this.templateOwnerId = templateOwnerId; + this.details = details; + this.sshkeyEnabled = sshkeyEnabled; + this.isDynamicallyScalable = isDynamicallyScalable; + this.isRoutingType = isRoutingType; + } + + UploadParamsBase(long userId, String name, String displayText, Boolean isPublic, Boolean isFeatured, + Boolean isExtractable, Long osTypeId, Long zoneId, Boolean bootable, long ownerId) { + this.userId = userId; + this.name = name; + this.displayText = displayText; + this.isPublic = isPublic; + this.featured = isFeatured; + this.isExtractable = isExtractable; + this.guestOSId = osTypeId; + this.zoneId = zoneId; + this.bootable = bootable; + this.templateOwnerId = ownerId; + } + + @Override + public boolean isIso() { + return isIso; + } + + @Override + public long getUserId() { + return userId; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getDisplayText() { + return displayText; + } + + @Override + public Integer getBits() { + return bits; + } + + @Override + public Boolean isPasswordEnabled() { + return passwordEnabled; + } + + @Override + public Boolean requiresHVM() { + return requiresHVM; + } + + @Override + public String getUrl() { + return null; + } + + @Override + public Boolean isPublic() { + return isPublic; + } + + @Override + public Boolean isFeatured() { + return featured; + } + + @Override + public Boolean isExtractable() { + return isExtractable; + } + + @Override + public String getFormat() { + return format; + } + + @Override + public Long getGuestOSId() { + return guestOSId; + } + + @Override + public Long getZoneId() { + return zoneId; + } + + @Override + public Hypervisor.HypervisorType getHypervisorType() { + return hypervisorType; + } + + @Override + public String getChecksum() { + return checksum; + } + + @Override + public Boolean isBootable() { + return bootable; + } + + @Override + public String getTemplateTag() { + return templateTag; + } + + @Override + public long getTemplateOwnerId() { + return templateOwnerId; + } + + @Override + public Map getDetails() { + return details; + } + + @Override + public Boolean isSshKeyEnabled() { + return sshkeyEnabled; + } + + @Override + public String getImageStoreUuid() { + return null; + } + + @Override + public Boolean isDynamicallyScalable() { + return isDynamicallyScalable; + } + + @Override + public Boolean isRoutingType() { + return isRoutingType; + } + + @Override + public boolean isDirectDownload() { + return false; + } + + void setIso(boolean iso) { + isIso = iso; + } + + void setBootable(Boolean bootable) { + this.bootable = bootable; + } + + void setBits(Integer bits) { + this.bits = bits; + } + + void setFormat(String format) { + this.format = format; + } + + void setRequiresHVM(Boolean requiresHVM) { + this.requiresHVM = requiresHVM; + } + + void setHypervisorType(Hypervisor.HypervisorType hypervisorType) { + this.hypervisorType = hypervisorType; + } +} diff --git a/server/src/main/java/com/cloud/template/TemplateAdapterBase.java b/server/src/main/java/com/cloud/template/TemplateAdapterBase.java index 5128476b201e..63d4792051f5 100644 --- a/server/src/main/java/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/main/java/com/cloud/template/TemplateAdapterBase.java @@ -23,6 +23,9 @@ import javax.inject.Inject; +import com.cloud.storage.upload.params.IsoUploadParams; +import com.cloud.storage.upload.params.TemplateUploadParams; +import com.cloud.storage.upload.params.UploadParams; import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.template.GetUploadParamsForTemplateCmd; import org.apache.commons.collections.CollectionUtils; @@ -288,59 +291,52 @@ public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocatio /** * Prepare upload parameters internal method for templates and ISOs local upload */ - private TemplateProfile prepareUploadParamsInternal(boolean isIso, long userId, String name, String displayText, - Integer bits, Boolean passwordEnabled, Boolean requiresHVM, - String url, Boolean isPublic, Boolean featured, - Boolean isExtractable, String format, Long guestOSId, - Long zoneId, HypervisorType hypervisorType, String chksum, - Boolean bootable, String templateTag, long templateOwnerId, - Map details, Boolean sshkeyEnabled, String imageStoreUuid, - Boolean isDynamicallyScalable, Boolean isRoutingType, - boolean directDownload) throws ResourceAllocationException { + private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws ResourceAllocationException { //check if the caller can operate with the template owner Account caller = CallContext.current().getCallingAccount(); - Account owner = _accountMgr.getAccount(templateOwnerId); + Account owner = _accountMgr.getAccount(params.getTemplateOwnerId()); _accountMgr.checkAccess(caller, null, true, owner); - boolean isRouting = (isRoutingType == null) ? false : isRoutingType; + boolean isRouting = (params.isRoutingType() == null) ? false : params.isRoutingType(); List zoneList = null; // ignore passed zoneId if we are using region wide image store List stores = _imgStoreDao.findRegionImageStores(); if (!(stores != null && stores.size() > 0)) { zoneList = new ArrayList<>(); - zoneList.add(zoneId); + zoneList.add(params.getZoneId()); } - if(!isIso && hypervisorType == HypervisorType.None) { - throw new InvalidParameterValueException("Hypervisor Type: " + hypervisorType + " is invalid. Supported Hypervisor types are " + if(!params.isIso() && params.getHypervisorType() == HypervisorType.None) { + throw new InvalidParameterValueException("Hypervisor Type: " + params.getHypervisorType() + " is invalid. Supported Hypervisor types are " + EnumUtils.listValues(HypervisorType.values()).replace("None, ", "")); } - return prepare(isIso, userId, name, displayText, bits, passwordEnabled, - requiresHVM, url, isPublic, featured, isExtractable, format, guestOSId, zoneList, - hypervisorType, chksum, bootable, templateTag, owner, details, sshkeyEnabled, imageStoreUuid, - isDynamicallyScalable, isRouting ? TemplateType.ROUTING : TemplateType.USER, directDownload); + return prepare(params.isIso(), params.getUserId(), params.getName(), params.getDisplayText(), params.getBits(), + params.isPasswordEnabled(), params.requiresHVM(), params.getUrl(), params.isPublic(), params.isFeatured(), + params.isExtractable(), params.getFormat(), params.getGuestOSId(), zoneList, + params.getHypervisorType(), params.getChecksum(), params.isBootable(), params.getTemplateTag(), owner, + params.getDetails(), params.isSshKeyEnabled(), params.getImageStoreUuid(), + params.isDynamicallyScalable(), isRouting ? TemplateType.ROUTING : TemplateType.USER, params.isDirectDownload()); } @Override public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException { - return prepareUploadParamsInternal(false, CallContext.current().getCallingUserId(), cmd.getName(), - cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), null, + UploadParams params = new TemplateUploadParams(CallContext.current().getCallingUserId(), cmd.getName(), + cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), - cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(), true, + cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(), cmd.getTemplateTag(), cmd.getEntityOwnerId(), cmd.getDetails(), cmd.isSshKeyEnabled(), - null, cmd.isDynamicallyScalable(), cmd.isRoutingType(), false); + cmd.isDynamicallyScalable(), cmd.isRoutingType()); + return prepareUploadParamsInternal(params); } @Override public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException { - return prepareUploadParamsInternal(true, CallContext.current().getCallingUserId(), cmd.getName(), - cmd.getDisplayText(), 64, false, true, null, - cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), ImageFormat.ISO.toString(), cmd.getOsTypeId(), - cmd.getZoneId(), HypervisorType.None, null, cmd.isBootable(), - null, cmd.getEntityOwnerId(), null, false, - null, false, false, false); + UploadParams params = new IsoUploadParams(CallContext.current().getCallingUserId(), cmd.getName(), + cmd.getDisplayText(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getOsTypeId(), + cmd.getZoneId(), cmd.isBootable(), cmd.getEntityOwnerId()); + return prepareUploadParamsInternal(params); } @Override From 955e42de857c11924b129965b68aa582173a414a Mon Sep 17 00:00:00 2001 From: nvazquez Date: Mon, 8 Apr 2019 23:31:44 -0300 Subject: [PATCH 4/6] Fix null boolean fields after refactor --- .../storage/upload/params/UploadParams.java | 18 +++---- .../upload/params/UploadParamsBase.java | 54 +++++++++---------- .../cloud/template/TemplateAdapterBase.java | 19 +++---- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java b/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java index 9d3ae2d07e01..0d42b760b6d9 100644 --- a/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java +++ b/server/src/main/java/com/cloud/storage/upload/params/UploadParams.java @@ -26,24 +26,24 @@ public interface UploadParams { String getName(); String getDisplayText(); Integer getBits(); - Boolean isPasswordEnabled(); - Boolean requiresHVM(); + boolean isPasswordEnabled(); + boolean requiresHVM(); String getUrl(); - Boolean isPublic(); - Boolean isFeatured(); - Boolean isExtractable(); + boolean isPublic(); + boolean isFeatured(); + boolean isExtractable(); String getFormat(); Long getGuestOSId(); Long getZoneId(); Hypervisor.HypervisorType getHypervisorType(); String getChecksum(); - Boolean isBootable(); + boolean isBootable(); String getTemplateTag(); long getTemplateOwnerId(); Map getDetails(); - Boolean isSshKeyEnabled(); + boolean isSshKeyEnabled(); String getImageStoreUuid(); - Boolean isDynamicallyScalable(); - Boolean isRoutingType(); + boolean isDynamicallyScalable(); + boolean isRoutingType(); boolean isDirectDownload(); } diff --git a/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java b/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java index 6b9a11206092..67b04f7b4800 100644 --- a/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java +++ b/server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java @@ -27,32 +27,32 @@ public abstract class UploadParamsBase implements UploadParams { private String name; private String displayText; private Integer bits; - private Boolean passwordEnabled; - private Boolean requiresHVM; - private Boolean isPublic; - private Boolean featured; - private Boolean isExtractable; + private boolean passwordEnabled; + private boolean requiresHVM; + private boolean isPublic; + private boolean featured; + private boolean isExtractable; private String format; private Long guestOSId; private Long zoneId; private Hypervisor.HypervisorType hypervisorType; private String checksum; - private Boolean bootable; + private boolean bootable; private String templateTag; private long templateOwnerId; private Map details; - private Boolean sshkeyEnabled; - private Boolean isDynamicallyScalable; - private Boolean isRoutingType; + private boolean sshkeyEnabled; + private boolean isDynamicallyScalable; + private boolean isRoutingType; UploadParamsBase(long userId, String name, String displayText, - Integer bits, Boolean passwordEnabled, Boolean requiresHVM, - Boolean isPublic, Boolean featured, - Boolean isExtractable, String format, Long guestOSId, + Integer bits, boolean passwordEnabled, boolean requiresHVM, + boolean isPublic, boolean featured, + boolean isExtractable, String format, Long guestOSId, Long zoneId, Hypervisor.HypervisorType hypervisorType, String checksum, String templateTag, long templateOwnerId, - Map details, Boolean sshkeyEnabled, - Boolean isDynamicallyScalable, Boolean isRoutingType) { + Map details, boolean sshkeyEnabled, + boolean isDynamicallyScalable, boolean isRoutingType) { this.userId = userId; this.name = name; this.displayText = displayText; @@ -75,8 +75,8 @@ public abstract class UploadParamsBase implements UploadParams { this.isRoutingType = isRoutingType; } - UploadParamsBase(long userId, String name, String displayText, Boolean isPublic, Boolean isFeatured, - Boolean isExtractable, Long osTypeId, Long zoneId, Boolean bootable, long ownerId) { + UploadParamsBase(long userId, String name, String displayText, boolean isPublic, boolean isFeatured, + boolean isExtractable, Long osTypeId, Long zoneId, boolean bootable, long ownerId) { this.userId = userId; this.name = name; this.displayText = displayText; @@ -115,12 +115,12 @@ public Integer getBits() { } @Override - public Boolean isPasswordEnabled() { + public boolean isPasswordEnabled() { return passwordEnabled; } @Override - public Boolean requiresHVM() { + public boolean requiresHVM() { return requiresHVM; } @@ -130,17 +130,17 @@ public String getUrl() { } @Override - public Boolean isPublic() { + public boolean isPublic() { return isPublic; } @Override - public Boolean isFeatured() { + public boolean isFeatured() { return featured; } @Override - public Boolean isExtractable() { + public boolean isExtractable() { return isExtractable; } @@ -170,7 +170,7 @@ public String getChecksum() { } @Override - public Boolean isBootable() { + public boolean isBootable() { return bootable; } @@ -190,7 +190,7 @@ public Map getDetails() { } @Override - public Boolean isSshKeyEnabled() { + public boolean isSshKeyEnabled() { return sshkeyEnabled; } @@ -200,12 +200,12 @@ public String getImageStoreUuid() { } @Override - public Boolean isDynamicallyScalable() { + public boolean isDynamicallyScalable() { return isDynamicallyScalable; } @Override - public Boolean isRoutingType() { + public boolean isRoutingType() { return isRoutingType; } @@ -218,7 +218,7 @@ void setIso(boolean iso) { isIso = iso; } - void setBootable(Boolean bootable) { + void setBootable(boolean bootable) { this.bootable = bootable; } @@ -230,7 +230,7 @@ void setFormat(String format) { this.format = format; } - void setRequiresHVM(Boolean requiresHVM) { + void setRequiresHVM(boolean requiresHVM) { this.requiresHVM = requiresHVM; } diff --git a/server/src/main/java/com/cloud/template/TemplateAdapterBase.java b/server/src/main/java/com/cloud/template/TemplateAdapterBase.java index 63d4792051f5..0e88c147f512 100644 --- a/server/src/main/java/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/main/java/com/cloud/template/TemplateAdapterBase.java @@ -29,6 +29,7 @@ import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd; import org.apache.cloudstack.api.command.user.template.GetUploadParamsForTemplateCmd; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -297,8 +298,6 @@ private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws Account owner = _accountMgr.getAccount(params.getTemplateOwnerId()); _accountMgr.checkAccess(caller, null, true, owner); - boolean isRouting = (params.isRoutingType() == null) ? false : params.isRoutingType(); - List zoneList = null; // ignore passed zoneId if we are using region wide image store List stores = _imgStoreDao.findRegionImageStores(); @@ -317,25 +316,27 @@ private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws params.isExtractable(), params.getFormat(), params.getGuestOSId(), zoneList, params.getHypervisorType(), params.getChecksum(), params.isBootable(), params.getTemplateTag(), owner, params.getDetails(), params.isSshKeyEnabled(), params.getImageStoreUuid(), - params.isDynamicallyScalable(), isRouting ? TemplateType.ROUTING : TemplateType.USER, params.isDirectDownload()); + params.isDynamicallyScalable(), params.isRoutingType() ? TemplateType.ROUTING : TemplateType.USER, params.isDirectDownload()); } @Override public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException { UploadParams params = new TemplateUploadParams(CallContext.current().getCallingUserId(), cmd.getName(), - cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), - cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), + cmd.getDisplayText(), cmd.getBits(), BooleanUtils.toBoolean(cmd.isPasswordEnabled()), + BooleanUtils.toBoolean(cmd.getRequiresHvm()), BooleanUtils.toBoolean(cmd.isPublic()), + BooleanUtils.toBoolean(cmd.isFeatured()), BooleanUtils.toBoolean(cmd.isExtractable()), cmd.getFormat(), cmd.getOsTypeId(), cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(), - cmd.getTemplateTag(), cmd.getEntityOwnerId(), cmd.getDetails(), cmd.isSshKeyEnabled(), - cmd.isDynamicallyScalable(), cmd.isRoutingType()); + cmd.getTemplateTag(), cmd.getEntityOwnerId(), cmd.getDetails(), BooleanUtils.toBoolean(cmd.isSshKeyEnabled()), + BooleanUtils.toBoolean(cmd.isDynamicallyScalable()), BooleanUtils.toBoolean(cmd.isRoutingType())); return prepareUploadParamsInternal(params); } @Override public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllocationException { UploadParams params = new IsoUploadParams(CallContext.current().getCallingUserId(), cmd.getName(), - cmd.getDisplayText(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getOsTypeId(), - cmd.getZoneId(), cmd.isBootable(), cmd.getEntityOwnerId()); + cmd.getDisplayText(), BooleanUtils.toBoolean(cmd.isPublic()), BooleanUtils.toBoolean(cmd.isFeatured()), + BooleanUtils.toBoolean(cmd.isExtractable()), cmd.getOsTypeId(), + cmd.getZoneId(), BooleanUtils.toBoolean(cmd.isBootable()), cmd.getEntityOwnerId()); return prepareUploadParamsInternal(params); } From 11dc1296557f9963c3498f2b9a1eac06ad960d65 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Sat, 13 Apr 2019 19:41:01 -0300 Subject: [PATCH 5/6] Fix for errors on local uploads --- ui/scripts/ui/dialog.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js index cce70e762078..c2ae135b6800 100644 --- a/ui/scripts/ui/dialog.js +++ b/ui/scripts/ui/dialog.js @@ -818,7 +818,16 @@ $form.find('.loading-overlay').remove(); $('div.loading-overlay').remove(); - cloudStack.dialog.error({ message: msg }); + if (!msg) { + msg = "Please enable SSL on your SSVM to allow uploading local files"; + } + cloudStack.dialog.notice({ message: msg }); + + $('.tooltip-box').remove(); + $formContainer.remove(); + $(this).dialog('destroy'); + + $('.hovered-elem').hide(); } } }; From 6cf163d73e48eb7c1cd65440a921542950493672 Mon Sep 17 00:00:00 2001 From: Anurag Awasthi Date: Thu, 18 Apr 2019 14:42:17 +0530 Subject: [PATCH 6/6] Make error message more generic as it's in dialog.js --- ui/scripts/ui/dialog.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js index c2ae135b6800..c8269ca38bf3 100644 --- a/ui/scripts/ui/dialog.js +++ b/ui/scripts/ui/dialog.js @@ -131,7 +131,7 @@ } }] }); - + return cloudStack.applyDefaultZindexAndOverlayOnJqueryDialogAndRemoveCloseButton($dialog); }; @@ -819,7 +819,7 @@ $('div.loading-overlay').remove(); if (!msg) { - msg = "Please enable SSL on your SSVM to allow uploading local files"; + msg = "Failed to upload file due to system misconfiguration. Please contact admin."; } cloudStack.dialog.notice({ message: msg }); @@ -1089,7 +1089,7 @@ } }] }); - + return cloudStack.applyDefaultZindexAndOverlayOnJqueryDialogAndRemoveCloseButton($dialog); }, @@ -1117,7 +1117,7 @@ } }] }); - + return cloudStack.applyDefaultZindexAndOverlayOnJqueryDialogAndRemoveCloseButton($dialog, 5001); } return false;