Search in sources :

Example 11 with ClustersResourceApi

use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerClusterDecommissionServiceTest method testRestartStaleServices.

@Test
public void testRestartStaleServices() throws CloudbreakException, ApiException {
    ClouderaManagerModificationService modificationService = Mockito.mock(ClouderaManagerModificationService.class);
    ClustersResourceApi clustersResourceApi = Mockito.mock(ClustersResourceApi.class);
    when(applicationContext.getBean(ClouderaManagerModificationService.class, stack, clientConfig)).thenReturn(modificationService);
    when(clouderaManagerApiFactory.getClustersResourceApi(v31Client)).thenReturn(clustersResourceApi);
    underTest.restartStaleServices(false);
    verify(applicationContext).getBean(ClouderaManagerModificationService.class, stack, clientConfig);
    verify(clouderaManagerApiFactory).getClustersResourceApi(v31Client);
    verify(modificationService).restartStaleServices(clustersResourceApi, false);
}
Also used : ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) Test(org.junit.Test)

Example 12 with ClustersResourceApi

use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSetupServiceTest method testInstallClusterWhenEverythingWorksFineShouldPollTheInsallProgress.

@Test
public void testInstallClusterWhenEverythingWorksFineShouldPollTheInsallProgress() throws ApiException {
    ClustersResourceApi clustersResourceApi = mock(ClustersResourceApi.class);
    ApiCommand apiCommand = mock(ApiCommand.class);
    ApiCluster apiCluster = mock(ApiCluster.class);
    ClusterCommand clusterCommand = mock(ClusterCommand.class);
    ClouderaManagerRepo clouderaManagerRepo = new ClouderaManagerRepo();
    clouderaManagerRepo.setVersion("6.2.0");
    ClouderaManagerResourceApi clouderaManagerResourceApi = mock(ClouderaManagerResourceApi.class);
    when(clusterComponentProvider.getClouderaManagerRepoDetails(anyLong())).thenReturn(clouderaManagerRepo);
    when(clouderaManagerApiFactory.getClustersResourceApi(any(ApiClient.class))).thenReturn(clustersResourceApi);
    when(clustersResourceApi.readCluster(anyString())).thenReturn(apiCluster);
    when(clusterCommandRepository.findTopByClusterIdAndClusterCommandType(anyLong(), any(ClusterCommandType.class))).thenReturn(Optional.empty());
    when(apiCommand.getId()).thenReturn(BigDecimal.ONE);
    when(clusterCommand.getCommandId()).thenReturn(BigDecimal.ONE);
    when(clouderaManagerApiFactory.getClouderaManagerResourceApi(any(ApiClient.class))).thenReturn(clouderaManagerResourceApi);
    when(clouderaManagerResourceApi.importClusterTemplate(anyBoolean(), any(ApiClusterTemplate.class))).thenReturn(apiCommand);
    when(clusterCommandRepository.save(any(ClusterCommand.class))).thenReturn(clusterCommand);
    when(clouderaManagerPollingServiceProvider.startPollingCmTemplateInstallation(any(Stack.class), any(ApiClient.class), any(BigDecimal.class))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().exit().build());
    underTest.installCluster("{}");
    verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmTemplateInstallation(any(Stack.class), any(ApiClient.class), any(BigDecimal.class));
    verify(clusterCommandRepository, times(1)).save(any(ClusterCommand.class));
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCluster(com.cloudera.api.swagger.model.ApiCluster) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) ClusterCommand(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommand) ClusterCommandType(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommandType) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) Test(org.junit.jupiter.api.Test)

Example 13 with ClustersResourceApi

use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSyncApiCommandIdCheckerTask method checkStatus.

@Override
public boolean checkStatus(ClouderaManagerCommandPollerObject pollerObject) {
    ApiClient apiClient = pollerObject.getApiClient();
    ClustersResourceApi api = clouderaManagerApiPojoFactory.getClustersResourceApi(apiClient);
    boolean result = false;
    ClouderaManagerSyncCommandPollerObject castedObj = cast(pollerObject);
    try {
        Optional<BigDecimal> commandId = syncApiCommandRetriever.getCommandId(castedObj.getCommandName(), api, castedObj.getStack());
        if (commandId.isPresent() && !commandId.get().equals(pollerObject.getId())) {
            LOGGER.debug("Found a new latest command ID for {} command: {}", castedObj.getCommandName(), commandId);
            result = true;
        } else if (castedObj.getId() != null && castedObj.getId().equals(commandId.orElse(null))) {
            LOGGER.debug("There is a valid command ID found: {}, but that is not the " + "newest command id of {}", castedObj.getId(), castedObj.getCommandName());
        } else {
            LOGGER.debug("Not found any new commandId yet - [recent_id: {}]", castedObj.getId());
        }
    } catch (ApiException | CloudbreakException e) {
        LOGGER.debug(String.format("Exception during polling the newest %s command.", castedObj.getCommandName()), e);
        result = false;
    }
    return result;
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ClouderaManagerSyncCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject) BigDecimal(java.math.BigDecimal) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 14 with ClustersResourceApi

use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerRangerUtil method getClusterName.

private String getClusterName(ApiClient client) throws ApiException {
    ClustersResourceApi clustersResource = clouderaManagerApiFactory.getClustersResourceApi(client);
    ApiClusterList clusterList = clustersResource.readClusters(null, null);
    return Iterables.getOnlyElement(clusterList.getItems()).getName();
}
Also used : ApiClusterList(com.cloudera.api.swagger.model.ApiClusterList) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi)

Example 15 with ClustersResourceApi

use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerModificationService method upscaleCluster.

@Override
public List<String> upscaleCluster(Map<HostGroup, Set<InstanceMetaData>> instanceMetaDatasByHostGroup) throws CloudbreakException {
    ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient);
    Set<InstanceMetaData> instanceMetaDatas = instanceMetaDatasByHostGroup.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
    try {
        LOGGER.debug("Starting cluster upscale with hosts: {}.", instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.joining(", ")));
        String clusterName = stack.getName();
        Set<String> clusterHostnames = getClusterHostnamesFromCM(clustersResourceApi, clusterName);
        List<ApiHost> hosts = getHostsFromCM();
        LOGGER.debug("Processing outdated cluster hosts. Cluster hostnames from CM: {}", clusterHostnames);
        setHostRackIdForOutdatedClusterHosts(instanceMetaDatas, clusterHostnames, hosts);
        LOGGER.debug("Processing upscaled cluster hosts.");
        Map<String, InstanceMetaData> upscaleInstancesMap = getInstancesMap(clusterHostnames, instanceMetaDatas, true);
        if (!upscaleInstancesMap.isEmpty()) {
            Map<String, ApiHost> upscaleHostsMap = getHostsMap(upscaleInstancesMap, hosts);
            setHostRackIdBatch(upscaleInstancesMap, upscaleHostsMap);
            ApiHostRefList bodyForAddHosts = createUpscaledHostRefList(upscaleInstancesMap, upscaleHostsMap);
            clustersResourceApi.addHosts(clusterName, bodyForAddHosts);
            activateParcels(clustersResourceApi);
            for (HostGroup hostGroup : instanceMetaDatasByHostGroup.keySet()) {
                ApiHostRefList bodyForApplyHostGroupRoles = getBodyForApplyHostGroupRoles(upscaleInstancesMap, upscaleHostsMap, hostGroup);
                applyHostGroupRolesOnUpscaledHosts(bodyForApplyHostGroupRoles, hostGroup.getName());
            }
        } else {
            redistributeParcelsForRecovery();
            activateParcels(clustersResourceApi);
        }
        deployClientConfig(clustersResourceApi, stack);
        clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack);
        LOGGER.debug("Cluster upscale completed.");
        return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).collect(Collectors.toList());
    } catch (ApiException e) {
        LOGGER.error(String.format("Failed to upscale. Response: %s", e.getResponseBody()), e);
        throw new CloudbreakException("Failed to upscale", e);
    }
}
Also used : ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)19 ApiException (com.cloudera.api.swagger.client.ApiException)8 ApiClient (com.cloudera.api.swagger.client.ApiClient)7 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)6 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)5 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)5 BigDecimal (java.math.BigDecimal)5 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)4 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)4 ApiHost (com.cloudera.api.swagger.model.ApiHost)3 ApiService (com.cloudera.api.swagger.model.ApiService)3 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)3 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 HostTemplatesResourceApi (com.cloudera.api.swagger.HostTemplatesResourceApi)2 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)2 MgmtServiceResourceApi (com.cloudera.api.swagger.MgmtServiceResourceApi)2 ParcelResourceApi (com.cloudera.api.swagger.ParcelResourceApi)2