17
17
18
18
package com .cloud .kubernetes .version ;
19
19
20
+ import java .net .MalformedURLException ;
20
21
import java .util .ArrayList ;
21
22
import java .util .List ;
22
23
26
27
import org .apache .cloudstack .api .ApiConstants ;
27
28
import org .apache .cloudstack .api .command .admin .kubernetes .version .AddKubernetesSupportedVersionCmd ;
28
29
import org .apache .cloudstack .api .command .admin .kubernetes .version .DeleteKubernetesSupportedVersionCmd ;
30
+ import org .apache .cloudstack .api .command .admin .kubernetes .version .GetUploadParamsForKubernetesSupportedVersionCmd ;
29
31
import org .apache .cloudstack .api .command .admin .kubernetes .version .UpdateKubernetesSupportedVersionCmd ;
30
32
import org .apache .cloudstack .api .command .user .iso .DeleteIsoCmd ;
33
+ import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
31
34
import org .apache .cloudstack .api .command .user .iso .RegisterIsoCmd ;
32
35
import org .apache .cloudstack .api .command .user .kubernetes .version .ListKubernetesSupportedVersionsCmd ;
36
+ import org .apache .cloudstack .api .response .GetUploadParamsResponse ;
33
37
import org .apache .cloudstack .api .response .KubernetesSupportedVersionResponse ;
34
38
import org .apache .cloudstack .api .response .ListResponse ;
35
39
import org .apache .cloudstack .context .CallContext ;
@@ -159,6 +163,33 @@ private List <KubernetesSupportedVersionVO> filterKubernetesSupportedVersions(Li
159
163
return versions ;
160
164
}
161
165
166
+ private GetUploadParamsResponse registerKubernetesVersionIsoForUpload (final Long zoneId , final String versionName , final String isoChecksum ) {
167
+ CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
168
+ String isoName = String .format ("%s-Kubernetes-Binaries-ISO" , versionName );
169
+ GetUploadParamsForIsoCmd uploadIso = new GetUploadParamsForIsoCmd ();
170
+ uploadIso = ComponentContext .inject (uploadIso );
171
+ uploadIso .setName (isoName );
172
+ uploadIso .setPublicIso (true );
173
+ if (zoneId != null ) {
174
+ uploadIso .setZoneId (zoneId );
175
+ }
176
+ uploadIso .setDisplayText (isoName );
177
+ uploadIso .setBootable (false );
178
+ if (StringUtils .isNotEmpty (isoChecksum )) {
179
+ uploadIso .setChecksum (isoChecksum );
180
+ }
181
+ uploadIso .setAccountName (accountManager .getSystemAccount ().getAccountName ());
182
+ uploadIso .setDomainId (accountManager .getSystemAccount ().getDomainId ());
183
+ try {
184
+ return templateService .registerIsoForPostUpload (uploadIso );
185
+ } catch (MalformedURLException | ResourceAllocationException e ) {
186
+ logger .error (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
187
+ throw new CloudRuntimeException (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
188
+ } finally {
189
+ CallContext .unregister ();
190
+ }
191
+ }
192
+
162
193
private VirtualMachineTemplate registerKubernetesVersionIso (final Long zoneId , final String versionName , final String isoUrl , final String isoChecksum , final boolean directDownload ) throws IllegalAccessException , NoSuchFieldException ,
163
194
IllegalArgumentException , ResourceAllocationException {
164
195
CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
@@ -301,21 +332,8 @@ public ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedV
301
332
return createKubernetesSupportedVersionListResponse (versions , versionsAndCount .second ());
302
333
}
303
334
304
- @ Override
305
- @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
306
- eventDescription = "Adding Kubernetes supported version" )
307
- public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
308
- if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
309
- throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
310
- }
311
- String name = cmd .getName ();
312
- final String semanticVersion = cmd .getSemanticVersion ();
313
- final Long zoneId = cmd .getZoneId ();
314
- final String isoUrl = cmd .getUrl ();
315
- final String isoChecksum = cmd .getChecksum ();
316
- final Integer minimumCpu = cmd .getMinimumCpu ();
317
- final Integer minimumRamSize = cmd .getMinimumRamSize ();
318
- final boolean isDirectDownload = cmd .isDirectDownload ();
335
+ private void validateKubernetesSupportedVersion (Long zoneId , String semanticVersion , Integer minimumCpu ,
336
+ Integer minimumRamSize , boolean isDirectDownload ) {
319
337
if (minimumCpu == null || minimumCpu < KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ) {
320
338
throw new InvalidParameterValueException (String .format ("Invalid value for %s parameter. Minimum %d vCPUs required." , ApiConstants .MIN_CPU_NUMBER , KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ));
321
339
}
@@ -334,6 +352,26 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
334
352
throw new InvalidParameterValueException (String .format ("Zone: %s supports only direct download Kubernetes versions" , zone .getName ()));
335
353
}
336
354
}
355
+ }
356
+
357
+ @ Override
358
+ @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
359
+ eventDescription = "Adding Kubernetes supported version" )
360
+ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
361
+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
362
+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
363
+ }
364
+ String name = cmd .getName ();
365
+ final String semanticVersion = cmd .getSemanticVersion ();
366
+ final Long zoneId = cmd .getZoneId ();
367
+ final String isoUrl = cmd .getUrl ();
368
+ final String isoChecksum = cmd .getChecksum ();
369
+ final Integer minimumCpu = cmd .getMinimumCpu ();
370
+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
371
+ final boolean isDirectDownload = cmd .isDirectDownload ();
372
+
373
+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , isDirectDownload );
374
+
337
375
if (StringUtils .isEmpty (isoUrl )) {
338
376
throw new InvalidParameterValueException (String .format ("Invalid URL for ISO specified, %s" , isoUrl ));
339
377
}
@@ -360,6 +398,30 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
360
398
return createKubernetesSupportedVersionResponse (supportedVersionVO );
361
399
}
362
400
401
+ @ Override
402
+ public GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload (GetUploadParamsForKubernetesSupportedVersionCmd cmd ) {
403
+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
404
+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
405
+ }
406
+ String name = cmd .getName ();
407
+ final String semanticVersion = cmd .getSemanticVersion ();
408
+ final Long zoneId = cmd .getZoneId ();
409
+ final String isoChecksum = cmd .getChecksum ();
410
+ final Integer minimumCpu = cmd .getMinimumCpu ();
411
+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
412
+
413
+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , false );
414
+
415
+ GetUploadParamsResponse response = registerKubernetesVersionIsoForUpload (zoneId , name , isoChecksum );
416
+
417
+ VMTemplateVO template = templateDao .findByUuid (response .getId ().toString ());
418
+ KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO (name , semanticVersion , template .getId (), zoneId , minimumCpu , minimumRamSize );
419
+ supportedVersionVO = kubernetesSupportedVersionDao .persist (supportedVersionVO );
420
+ CallContext .current ().putContextParameter (KubernetesSupportedVersion .class , supportedVersionVO .getUuid ());
421
+
422
+ return response ;
423
+ }
424
+
363
425
@ Override
364
426
@ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_DELETE ,
365
427
eventDescription = "deleting Kubernetes supported version" , async = true )
@@ -428,6 +490,7 @@ public List<Class<?>> getCommands() {
428
490
return cmdList ;
429
491
}
430
492
cmdList .add (AddKubernetesSupportedVersionCmd .class );
493
+ cmdList .add (GetUploadParamsForKubernetesSupportedVersionCmd .class );
431
494
cmdList .add (ListKubernetesSupportedVersionsCmd .class );
432
495
cmdList .add (DeleteKubernetesSupportedVersionCmd .class );
433
496
cmdList .add (UpdateKubernetesSupportedVersionCmd .class );
0 commit comments