@Test void upscaleClusterListHostsException() throws Exception { when(clustersResourceApi.listHosts(eq(STACK_NAME), eq(null), eq(null))).thenThrow(new ApiException("Failed to get hosts")); when(clouderaManagerApiFactory.getClustersResourceApi(eq(apiClientMock))).thenReturn(clustersResourceApi); InstanceMetaData instanceMetaData = new InstanceMetaData(); instanceMetaData.setDiscoveryFQDN("upscaled"); List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData); Exception exception = assertThrows(CloudbreakException.class, () -> underTest.upscaleCluster(hostGroup, instanceMetaDataList)); assertEquals("Failed to upscale", exception.getMessage()); }
@Override public List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas) throws CloudbreakException { ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient); try { String clusterName = stack.getName(); List<String> upscaleHostNames = getUpscaleHosts(clustersResourceApi, clusterName, instanceMetaDatas); if (!upscaleHostNames.isEmpty()) { List<ApiHost> hosts = clouderaManagerApiFactory.getHostsResourceApi(apiClient).readHosts(null, null, SUMMARY).getItems(); ApiHostRefList body = createUpscaledHostRefList(upscaleHostNames, hosts); clustersResourceApi.addHosts(clusterName, body); activateParcel(clustersResourceApi); applyHostGroupRolesOnUpscaledHosts(body, hostGroup.getName()); } else { redistributeParcelsForRecovery(); activateParcel(clustersResourceApi); clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack); } return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList()); } catch (ApiException e) { LOGGER.warn("Failed to upscale: {}", e.getResponseBody(), e); throw new CloudbreakException("Failed to upscale", e); } }
ClouderaManagerModificationService implements ClusterModificationService { @Override public List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas) throws CloudbreakException { ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient); try { String clusterName = stack.getName(); List<String> upscaleHostNames = getUpscaleHosts(clustersResourceApi, clusterName, instanceMetaDatas); if (!upscaleHostNames.isEmpty()) { List<ApiHost> hosts = clouderaManagerApiFactory.getHostsResourceApi(apiClient).readHosts(null, null, SUMMARY).getItems(); ApiHostRefList body = createUpscaledHostRefList(upscaleHostNames, hosts); clustersResourceApi.addHosts(clusterName, body); activateParcel(clustersResourceApi); applyHostGroupRolesOnUpscaledHosts(body, hostGroup.getName()); } else { redistributeParcelsForRecovery(); activateParcel(clustersResourceApi); clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack); } return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList()); } catch (ApiException e) { LOGGER.warn("Failed to upscale: {}", e.getResponseBody(), e); throw new CloudbreakException("Failed to upscale", e); } } }
ClouderaManagerModificationService implements ClusterModificationService { @Override public List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas) throws CloudbreakException { ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient); try { String clusterName = stack.getName(); List<String> upscaleHostNames = getUpscaleHosts(clustersResourceApi, clusterName, instanceMetaDatas); if (!upscaleHostNames.isEmpty()) { List<ApiHost> hosts = clouderaManagerApiFactory.getHostsResourceApi(apiClient).readHosts(null, null, SUMMARY).getItems(); ApiHostRefList body = createUpscaledHostRefList(upscaleHostNames, hosts); clustersResourceApi.addHosts(clusterName, body); activateParcel(clustersResourceApi); applyHostGroupRolesOnUpscaledHosts(body, hostGroup.getName()); } else { redistributeParcelsForRecovery(); activateParcel(clustersResourceApi); clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack); } return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList()); } catch (ApiException e) { LOGGER.warn("Failed to upscale: {}", e.getResponseBody(), e); throw new CloudbreakException("Failed to upscale", e); } } ClouderaManagerModificationService(Stack stack, HttpClientConfig clientConfig); }
ClouderaManagerModificationService implements ClusterModificationService { @Override public List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas) throws CloudbreakException { ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient); try { String clusterName = stack.getName(); List<String> upscaleHostNames = getUpscaleHosts(clustersResourceApi, clusterName, instanceMetaDatas); if (!upscaleHostNames.isEmpty()) { List<ApiHost> hosts = clouderaManagerApiFactory.getHostsResourceApi(apiClient).readHosts(null, null, SUMMARY).getItems(); ApiHostRefList body = createUpscaledHostRefList(upscaleHostNames, hosts); clustersResourceApi.addHosts(clusterName, body); activateParcel(clustersResourceApi); applyHostGroupRolesOnUpscaledHosts(body, hostGroup.getName()); } else { redistributeParcelsForRecovery(); activateParcel(clustersResourceApi); clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack); } return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList()); } catch (ApiException e) { LOGGER.warn("Failed to upscale: {}", e.getResponseBody(), e); throw new CloudbreakException("Failed to upscale", e); } } ClouderaManagerModificationService(Stack stack, HttpClientConfig clientConfig); @PostConstruct void initApiClient(); @Override List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas); @Override void cleanupCluster(Telemetry telemetry); @Override void upgradeClusterRuntime(Set<ClusterComponent> components, boolean patchUpgrade); void restartStaleServices(MgmtServiceResourceApi mgmtServiceResourceApi, ClustersResourceApi clustersResourceApi); @Override void stopCluster(boolean disableKnoxAutorestart); @Override int startCluster(Set<InstanceMetaData> hostsInCluster); @Override Map<String, String> getComponentsByCategory(String blueprintName, String hostGroupName); @Override String getStackRepositoryJson(StackRepoDetails repoDetails, String stackRepoId); @Override Map<String, String> gatherInstalledParcels(String stackName); @Override void removeUnusedParcels(Set<ClusterComponent> usedParcelComponents); @Override void restartAll(); }
ClouderaManagerModificationService implements ClusterModificationService { @Override public List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas) throws CloudbreakException { ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient); try { String clusterName = stack.getName(); List<String> upscaleHostNames = getUpscaleHosts(clustersResourceApi, clusterName, instanceMetaDatas); if (!upscaleHostNames.isEmpty()) { List<ApiHost> hosts = clouderaManagerApiFactory.getHostsResourceApi(apiClient).readHosts(null, null, SUMMARY).getItems(); ApiHostRefList body = createUpscaledHostRefList(upscaleHostNames, hosts); clustersResourceApi.addHosts(clusterName, body); activateParcel(clustersResourceApi); applyHostGroupRolesOnUpscaledHosts(body, hostGroup.getName()); } else { redistributeParcelsForRecovery(); activateParcel(clustersResourceApi); clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack); } return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList()); } catch (ApiException e) { LOGGER.warn("Failed to upscale: {}", e.getResponseBody(), e); throw new CloudbreakException("Failed to upscale", e); } } ClouderaManagerModificationService(Stack stack, HttpClientConfig clientConfig); @PostConstruct void initApiClient(); @Override List<String> upscaleCluster(HostGroup hostGroup, Collection<InstanceMetaData> instanceMetaDatas); @Override void cleanupCluster(Telemetry telemetry); @Override void upgradeClusterRuntime(Set<ClusterComponent> components, boolean patchUpgrade); void restartStaleServices(MgmtServiceResourceApi mgmtServiceResourceApi, ClustersResourceApi clustersResourceApi); @Override void stopCluster(boolean disableKnoxAutorestart); @Override int startCluster(Set<InstanceMetaData> hostsInCluster); @Override Map<String, String> getComponentsByCategory(String blueprintName, String hostGroupName); @Override String getStackRepositoryJson(StackRepoDetails repoDetails, String stackRepoId); @Override Map<String, String> gatherInstalledParcels(String stackName); @Override void removeUnusedParcels(Set<ClusterComponent> usedParcelComponents); @Override void restartAll();  }