Search in sources :

Example 1 with KubernetesClusterVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVO in project cloudstack by apache.

the class KubernetesClusterDestroyWorker method updateKubernetesClusterEntryForGC.

private boolean updateKubernetesClusterEntryForGC() {
    KubernetesClusterVO kubernetesClusterVO = kubernetesClusterDao.findById(kubernetesCluster.getId());
    kubernetesClusterVO.setCheckForGc(true);
    return kubernetesClusterDao.update(kubernetesCluster.getId(), kubernetesClusterVO);
}
Also used : KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO)

Example 2 with KubernetesClusterVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVO in project cloudstack by apache.

the class KubernetesVersionManagerImpl method deleteKubernetesSupportedVersion.

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_DELETE, eventDescription = "Deleting Kubernetes supported version", async = true)
public boolean deleteKubernetesSupportedVersion(final DeleteKubernetesSupportedVersionCmd cmd) {
    if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
        throw new CloudRuntimeException("Kubernetes Service plugin is disabled");
    }
    final Long versionId = cmd.getId();
    KubernetesSupportedVersion version = kubernetesSupportedVersionDao.findById(versionId);
    if (version == null) {
        throw new InvalidParameterValueException("Invalid Kubernetes version id specified");
    }
    List<KubernetesClusterVO> clusters = kubernetesClusterDao.listAllByKubernetesVersion(versionId);
    if (clusters.size() > 0) {
        throw new CloudRuntimeException(String.format("Unable to delete Kubernetes version ID: %s. Existing clusters currently using the version.", version.getUuid()));
    }
    VMTemplateVO template = templateDao.findByIdIncludingRemoved(version.getIsoId());
    if (template == null) {
        LOGGER.warn(String.format("Unable to find ISO associated with supported Kubernetes version ID: %s", version.getUuid()));
    }
    if (template != null && template.getRemoved() == null) {
        // Delete ISO
        try {
            deleteKubernetesVersionIso(template.getId());
        } catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException ex) {
            LOGGER.error(String.format("Unable to delete binaries ISO ID: %s associated with supported kubernetes version ID: %s", template.getUuid(), version.getUuid()), ex);
            throw new CloudRuntimeException(String.format("Unable to delete binaries ISO ID: %s associated with supported kubernetes version ID: %s", template.getUuid(), version.getUuid()));
        }
    }
    return kubernetesSupportedVersionDao.remove(version.getId());
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) ActionEvent(com.cloud.event.ActionEvent)

Example 3 with KubernetesClusterVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVO in project cloudstack by apache.

the class KubernetesClusterScaleWorker method updateKubernetesClusterEntry.

private KubernetesClusterVO updateKubernetesClusterEntry(final Long newSize, final ServiceOffering newServiceOffering) throws CloudRuntimeException {
    final ServiceOffering serviceOffering = newServiceOffering == null ? serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId()) : newServiceOffering;
    final Long serviceOfferingId = newServiceOffering == null ? null : serviceOffering.getId();
    final long size = newSize == null ? kubernetesCluster.getTotalNodeCount() : (newSize + kubernetesCluster.getControlNodeCount());
    final long cores = serviceOffering.getCpu() * size;
    final long memory = serviceOffering.getRamSize() * size;
    KubernetesClusterVO kubernetesClusterVO = updateKubernetesClusterEntry(cores, memory, newSize, serviceOfferingId, kubernetesCluster.getAutoscalingEnabled(), kubernetesCluster.getMinSize(), kubernetesCluster.getMaxSize());
    if (kubernetesClusterVO == null) {
        logTransitStateAndThrow(Level.ERROR, String.format("Scaling Kubernetes cluster %s failed, unable to update Kubernetes cluster", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
    }
    return kubernetesClusterVO;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO)

Example 4 with KubernetesClusterVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVO in project cloudstack by apache.

the class KubernetesVersionServiceTest method deleteKubernetesSupportedVersionExistingClustersTest.

@Test(expected = CloudRuntimeException.class)
public void deleteKubernetesSupportedVersionExistingClustersTest() {
    DeleteKubernetesSupportedVersionCmd cmd = Mockito.mock(DeleteKubernetesSupportedVersionCmd.class);
    AccountVO account = new AccountVO("admin", 1L, "", Account.ACCOUNT_TYPE_ADMIN, "uuid");
    UserVO user = new UserVO(1, "adminuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    when(kubernetesSupportedVersionDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(KubernetesSupportedVersionVO.class));
    List<KubernetesClusterVO> clusters = new ArrayList<>();
    clusters.add(Mockito.mock(KubernetesClusterVO.class));
    when(kubernetesClusterDao.listAllByKubernetesVersion(Mockito.anyLong())).thenReturn(clusters);
    kubernetesVersionService.deleteKubernetesSupportedVersion(cmd);
}
Also used : UserVO(com.cloud.user.UserVO) KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO) ArrayList(java.util.ArrayList) DeleteKubernetesSupportedVersionCmd(org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd) AccountVO(com.cloud.user.AccountVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with KubernetesClusterVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVO in project cloudstack by apache.

the class KubernetesVersionServiceTest method deleteKubernetesSupportedVersionTest.

@Test
public void deleteKubernetesSupportedVersionTest() {
    DeleteKubernetesSupportedVersionCmd cmd = Mockito.mock(DeleteKubernetesSupportedVersionCmd.class);
    AccountVO account = new AccountVO("admin", 1L, "", Account.ACCOUNT_TYPE_ADMIN, "uuid");
    UserVO user = new UserVO(1, "adminuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    when(kubernetesSupportedVersionDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(KubernetesSupportedVersionVO.class));
    List<KubernetesClusterVO> clusters = new ArrayList<>();
    when(kubernetesClusterDao.listAllByKubernetesVersion(Mockito.anyLong())).thenReturn(clusters);
    when(templateDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(VMTemplateVO.class));
    PowerMockito.mockStatic(ComponentContext.class);
    when(ComponentContext.inject(Mockito.any(DeleteIsoCmd.class))).thenReturn(new DeleteIsoCmd());
    when(templateService.deleteIso(Mockito.any(DeleteIsoCmd.class))).thenReturn(true);
    when(kubernetesClusterDao.remove(Mockito.anyLong())).thenReturn(true);
    kubernetesVersionService.deleteKubernetesSupportedVersion(cmd);
}
Also used : UserVO(com.cloud.user.UserVO) KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO) DeleteKubernetesSupportedVersionCmd(org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd) AccountVO(com.cloud.user.AccountVO) DeleteIsoCmd(org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

KubernetesClusterVO (com.cloud.kubernetes.cluster.KubernetesClusterVO)9 ArrayList (java.util.ArrayList)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 AccountVO (com.cloud.user.AccountVO)2 UserVO (com.cloud.user.UserVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DeleteKubernetesSupportedVersionCmd (org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ActionEvent (com.cloud.event.ActionEvent)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ManagementServerException (com.cloud.exception.ManagementServerException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 LaunchPermissionVO (com.cloud.storage.LaunchPermissionVO)1 UserVm (com.cloud.uservm.UserVm)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 InternalIdentity (org.apache.cloudstack.api.InternalIdentity)1 DeleteIsoCmd (org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd)1