-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
- Loading branch information
There are no files selected for viewing
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L76
|
||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L78
|
||
} | ||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L81
|
||
} | ||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L83-L84
|
||
|
||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L86-L88
|
||
|
||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L90-L92
|
||
|
||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L94-L96
|
||
|
||
@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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L99-L101
|
||
|
||
@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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L104-L106
|
||
|
||
///////////////////////////////////////////////////// | ||
/////////////// 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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L112
|
||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L114
|
||
} | ||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L116-L117
|
||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L119
|
||
} | ||
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 Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java#L121-L126
|
||
} |