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);
}
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());
}
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;
}
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);
}
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);
}
Aggregations