Skip to content

Commit

Permalink
Allow uploading of ISO for creating kubernetes supported versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh92 committed Aug 23, 2024
1 parent b215abc commit 6d378b5
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ public Long getProjectId() {
return projectId;
}

public void setName(String name) {
this.name = name;
}

Check warning on line 86 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L84-L86

Added lines #L84 - L86 were not covered by tests

public void setFormat(String format) {
this.format = format;
}

Check warning on line 90 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L88-L90

Added lines #L88 - L90 were not covered by tests

public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}

Check warning on line 94 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L92-L94

Added lines #L92 - L94 were not covered by tests

public void setChecksum(String checksum) {
this.checksum = checksum;
}

Check warning on line 98 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L96-L98

Added lines #L96 - L98 were not covered by tests

public void setAccountName(String accountName) {
this.accountName = accountName;
}

Check warning on line 102 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L100-L102

Added lines #L100 - L102 were not covered by tests

public void setDomainId(Long domainId) {
this.domainId = domainId;
}

Check warning on line 106 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L104-L106

Added lines #L104 - L106 were not covered by tests

public void setProjectId(Long projectId) {
this.projectId = projectId;
}

Check warning on line 110 in api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java#L108-L110

Added lines #L108 - L110 were not covered by tests

public GetUploadParamsResponse createGetUploadParamsResponse(UUID id, URL postURL, String metadata, String timeout, String signature) {
return new GetUploadParamsResponse(id, postURL, metadata, timeout, signature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ public Long getOsTypeId() {
return osTypeId;
}

public void setBootable(Boolean bootable) {
this.bootable = bootable;
}

Check warning on line 109 in api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java#L107-L109

Added lines #L107 - L109 were not covered by tests

public void setDisplayText(String displayText) {
this.displayText = displayText;
}

Check warning on line 113 in api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java#L111-L113

Added lines #L111 - L113 were not covered by tests

public void setFeatured(Boolean featured) {
this.featured = featured;
}

Check warning on line 117 in api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java#L115-L117

Added lines #L115 - L117 were not covered by tests

public void setPublicIso(Boolean publicIso) {
this.publicIso = publicIso;
}

Check warning on line 121 in api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java#L119-L121

Added lines #L119 - L121 were not covered by tests

public void setExtractable(Boolean extractable) {
this.extractable = extractable;
}

Check warning on line 125 in api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java#L123-L125

Added lines #L123 - L125 were not covered by tests

public void setOsTypeId(Long osTypeId) {
this.osTypeId = osTypeId;
}

Check warning on line 129 in api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java#L127-L129

Added lines #L127 - L129 were not covered by tests

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public GetUploadParamsResponse() {
setObjectName("getuploadparams");
}

public UUID getId() {
return id;
}

Check warning on line 67 in api/src/main/java/org/apache/cloudstack/api/response/GetUploadParamsResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/GetUploadParamsResponse.java#L65-L67

Added lines #L65 - L67 were not covered by tests

public void setId(UUID id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.cloud.kubernetes.version;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -26,10 +27,13 @@
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.GetUploadParamsForKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.UpdateKubernetesSupportedVersionCmd;
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.kubernetes.version.ListKubernetesSupportedVersionsCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.context.CallContext;
Expand Down Expand Up @@ -159,6 +163,33 @@ private List <KubernetesSupportedVersionVO> filterKubernetesSupportedVersions(Li
return versions;
}

private GetUploadParamsResponse registerKubernetesVersionIsoForUpload(final Long zoneId, final String versionName, final String isoChecksum) {
CallContext.register(CallContext.current(), ApiCommandResourceType.Iso);
String isoName = String.format("%s-Kubernetes-Binaries-ISO", versionName);
GetUploadParamsForIsoCmd uploadIso = new GetUploadParamsForIsoCmd();
uploadIso = ComponentContext.inject(uploadIso);
uploadIso.setName(isoName);
uploadIso.setPublicIso(true);

Check warning on line 172 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L166-L172

Added lines #L166 - L172 were not covered by tests
if (zoneId != null) {
uploadIso.setZoneId(zoneId);

Check warning on line 174 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L174

Added line #L174 was not covered by tests
}
uploadIso.setDisplayText(isoName);
uploadIso.setBootable(false);

Check warning on line 177 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L176-L177

Added lines #L176 - L177 were not covered by tests
if (StringUtils.isNotEmpty(isoChecksum)) {
uploadIso.setChecksum(isoChecksum);

Check warning on line 179 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L179

Added line #L179 was not covered by tests
}
uploadIso.setAccountName(accountManager.getSystemAccount().getAccountName());
uploadIso.setDomainId(accountManager.getSystemAccount().getDomainId());
try {
return templateService.registerIsoForPostUpload(uploadIso);
} catch (MalformedURLException | ResourceAllocationException e) {
logger.error(String.format("Unable to register binaries ISO for supported kubernetes version, %s", versionName), e);
throw new CloudRuntimeException(String.format("Unable to register binaries ISO for supported kubernetes version, %s", versionName), e);

Check warning on line 187 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L181-L187

Added lines #L181 - L187 were not covered by tests
} finally {
CallContext.unregister();

Check warning on line 189 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L189

Added line #L189 was not covered by tests
}
}

Check warning on line 191 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L191

Added line #L191 was not covered by tests

private VirtualMachineTemplate registerKubernetesVersionIso(final Long zoneId, final String versionName, final String isoUrl, final String isoChecksum, final boolean directDownload) throws IllegalAccessException, NoSuchFieldException,
IllegalArgumentException, ResourceAllocationException {
CallContext.register(CallContext.current(), ApiCommandResourceType.Iso);
Expand Down Expand Up @@ -301,21 +332,8 @@ public ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedV
return createKubernetesSupportedVersionListResponse(versions, versionsAndCount.second());
}

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_ADD,
eventDescription = "Adding Kubernetes supported version")
public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final AddKubernetesSupportedVersionCmd cmd) {
if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
throw new CloudRuntimeException("Kubernetes Service plugin is disabled");
}
String name = cmd.getName();
final String semanticVersion = cmd.getSemanticVersion();
final Long zoneId = cmd.getZoneId();
final String isoUrl = cmd.getUrl();
final String isoChecksum = cmd.getChecksum();
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();
final boolean isDirectDownload = cmd.isDirectDownload();
private void validateKubernetesSupportedVersion(Long zoneId, String semanticVersion, Integer minimumCpu,
Integer minimumRamSize, boolean isDirectDownload) {
if (minimumCpu == null || minimumCpu < KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU) {
throw new InvalidParameterValueException(String.format("Invalid value for %s parameter. Minimum %d vCPUs required.", ApiConstants.MIN_CPU_NUMBER, KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU));
}
Expand All @@ -334,6 +352,26 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
throw new InvalidParameterValueException(String.format("Zone: %s supports only direct download Kubernetes versions", zone.getName()));
}
}
}

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_ADD,
eventDescription = "Adding Kubernetes supported version")
public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final AddKubernetesSupportedVersionCmd cmd) {
if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
throw new CloudRuntimeException("Kubernetes Service plugin is disabled");

Check warning on line 362 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L362

Added line #L362 was not covered by tests
}
String name = cmd.getName();
final String semanticVersion = cmd.getSemanticVersion();
final Long zoneId = cmd.getZoneId();
final String isoUrl = cmd.getUrl();
final String isoChecksum = cmd.getChecksum();
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();
final boolean isDirectDownload = cmd.isDirectDownload();

validateKubernetesSupportedVersion(zoneId, semanticVersion, minimumCpu, minimumRamSize, isDirectDownload);

if (StringUtils.isEmpty(isoUrl)) {
throw new InvalidParameterValueException(String.format("Invalid URL for ISO specified, %s", isoUrl));
}
Expand All @@ -360,6 +398,30 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
return createKubernetesSupportedVersionResponse(supportedVersionVO);
}

@Override
public GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload(GetUploadParamsForKubernetesSupportedVersionCmd cmd) {

Check warning on line 402 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L402

Added line #L402 was not covered by tests
if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
throw new CloudRuntimeException("Kubernetes Service plugin is disabled");

Check warning on line 404 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L404

Added line #L404 was not covered by tests
}
String name = cmd.getName();
final String semanticVersion = cmd.getSemanticVersion();
final Long zoneId = cmd.getZoneId();
final String isoChecksum = cmd.getChecksum();
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();

Check warning on line 411 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L406-L411

Added lines #L406 - L411 were not covered by tests

validateKubernetesSupportedVersion(zoneId, semanticVersion, minimumCpu, minimumRamSize, false);

Check warning on line 413 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L413

Added line #L413 was not covered by tests

GetUploadParamsResponse response = registerKubernetesVersionIsoForUpload(zoneId, name, isoChecksum);

Check warning on line 415 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L415

Added line #L415 was not covered by tests

VMTemplateVO template = templateDao.findByUuid(response.getId().toString());
KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO(name, semanticVersion, template.getId(), zoneId, minimumCpu, minimumRamSize);
supportedVersionVO = kubernetesSupportedVersionDao.persist(supportedVersionVO);
CallContext.current().putContextParameter(KubernetesSupportedVersion.class, supportedVersionVO.getUuid());

Check warning on line 420 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L417-L420

Added lines #L417 - L420 were not covered by tests

return response;
}

Check warning on line 423 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L422-L423

Added lines #L422 - L423 were not covered by tests

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_DELETE,
eventDescription = "deleting Kubernetes supported version", async = true)
Expand Down Expand Up @@ -428,6 +490,7 @@ public List<Class<?>> getCommands() {
return cmdList;
}
cmdList.add(AddKubernetesSupportedVersionCmd.class);
cmdList.add(GetUploadParamsForKubernetesSupportedVersionCmd.class);

Check warning on line 493 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java#L493

Added line #L493 was not covered by tests
cmdList.add(ListKubernetesSupportedVersionsCmd.class);
cmdList.add(DeleteKubernetesSupportedVersionCmd.class);
cmdList.add(UpdateKubernetesSupportedVersionCmd.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.GetUploadParamsForKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.UpdateKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.user.kubernetes.version.ListKubernetesSupportedVersionsCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
import org.apache.cloudstack.api.response.ListResponse;

Expand All @@ -31,6 +33,7 @@ public interface KubernetesVersionService extends PluggableService {
static final String MIN_KUBERNETES_VERSION = "1.11.0";
ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedVersions(ListKubernetesSupportedVersionsCmd cmd);
KubernetesSupportedVersionResponse addKubernetesSupportedVersion(AddKubernetesSupportedVersionCmd cmd) throws CloudRuntimeException;
GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload(GetUploadParamsForKubernetesSupportedVersionCmd cmd);
boolean deleteKubernetesSupportedVersion(DeleteKubernetesSupportedVersionCmd cmd) throws CloudRuntimeException;
KubernetesSupportedVersionResponse updateKubernetesSupportedVersion(UpdateKubernetesSupportedVersionCmd cmd) throws CloudRuntimeException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// 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.admin.kubernetes.version;

import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.kubernetes.version.KubernetesSupportedVersion;
import com.cloud.kubernetes.version.KubernetesVersionService;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.AbstractGetUploadParamsCmd;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang3.StringUtils;

import javax.inject.Inject;

@APICommand(name = "getUploadParamsForKubernetesSupportedVersion",
description = "Add a supported Kubernetes version",
responseObject = KubernetesSupportedVersionResponse.class,
responseView = ResponseObject.ResponseView.Full,
entityType = {KubernetesSupportedVersion.class},
authorized = {RoleType.Admin})
public class GetUploadParamsForKubernetesSupportedVersionCmd extends AbstractGetUploadParamsCmd implements AdminCmd {

@Inject
private KubernetesVersionService kubernetesVersionService;

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name = ApiConstants.SEMANTIC_VERSION, type = CommandType.STRING, required = true,
description = "the semantic version of the Kubernetes version. It needs to be specified in MAJOR.MINOR.PATCH format")
private String semanticVersion;

@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING,
description = "the checksum value of the binaries ISO. " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
private String checksum;

@Parameter(name = ApiConstants.MIN_CPU_NUMBER, type = CommandType.INTEGER, required = true,
description = "the minimum number of CPUs to be set with the Kubernetes version")
private Integer minimumCpu;

@Parameter(name = ApiConstants.MIN_MEMORY, type = CommandType.INTEGER, required = true,
description = "the minimum RAM size in MB to be set with the Kubernetes version")
private Integer minimumRamSize;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public String getSemanticVersion() {

Check warning on line 76 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L76

Added line #L76 was not covered by tests
if(StringUtils.isEmpty(semanticVersion)) {
throw new InvalidParameterValueException("Version can not be null");

Check warning on line 78 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L78

Added line #L78 was not covered by tests
}
if(!semanticVersion.matches("[0-9]+(\\.[0-9]+)*")) {
throw new IllegalArgumentException("Invalid version format. Semantic version needed");

Check warning on line 81 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L81

Added line #L81 was not covered by tests
}
return semanticVersion;
}

Check warning on line 84 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L83-L84

Added lines #L83 - L84 were not covered by tests

public String getChecksum() {
return checksum;
}

Check warning on line 88 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L86-L88

Added lines #L86 - L88 were not covered by tests

public Integer getMinimumCpu() {
return minimumCpu;
}

Check warning on line 92 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L90-L92

Added lines #L90 - L92 were not covered by tests

public Integer getMinimumRamSize() {
return minimumRamSize;
}

Check warning on line 96 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L94-L96

Added lines #L94 - L96 were not covered by tests

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccountId();
}

Check warning on line 101 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L99-L101

Added lines #L99 - L101 were not covered by tests

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.KubernetesSupportedVersion;
}

Check warning on line 106 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L104-L106

Added lines #L104 - L106 were not covered by tests

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ServerApiException, ConcurrentOperationException {

Check warning on line 112 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L112

Added line #L112 was not covered by tests
if (getZoneId() <= 0) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid zoneid");

Check warning on line 114 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L114

Added line #L114 was not covered by tests
}
try {
GetUploadParamsResponse response = kubernetesVersionService.registerKubernetesSupportedVersionForPostUpload(this);

Check warning on line 117 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L116-L117

Added lines #L116 - L117 were not covered by tests
if (response == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Kubernetes supported version");

Check warning on line 119 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L119

Added line #L119 was not covered by tests
}
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (CloudRuntimeException ex) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}

Check warning on line 126 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java

View check run for this annotation

Codecov / codecov/patch

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L121-L126

Added lines #L121 - L126 were not covered by tests
}
8 changes: 8 additions & 0 deletions ui/src/config/section/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ export default {
popup: true,
component: shallowRef(defineAsyncComponent(() => import('@/views/image/AddKubernetesSupportedVersion.vue')))
},
{
api: 'addKubernetesSupportedVersion',
icon: 'cloud-upload-outlined',
label: 'label.kubernetes.version.add.from.local',
listView: true,
popup: true,
component: shallowRef(defineAsyncComponent(() => import('@/views/image/AddKubernetesSupportedVersion.vue')))
},
{
api: 'updateKubernetesSupportedVersion',
icon: 'edit-outlined',
Expand Down
3 changes: 3 additions & 0 deletions ui/src/views/AutogenView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,9 @@ export default {
if (possibleApi === 'listTemplates') {
params.templatefilter = 'executable'
} else if (possibleApi === 'listIsos') {
if (this.$route.path.startsWith('/kubernetesiso')) {
params.bootable = false
}
params.isofilter = 'executable'
} else if (possibleApi === 'listHosts') {
params.type = 'routing'
Expand Down
Loading

0 comments on commit 6d378b5

Please sign in to comment.