Search in sources :

Example 6 with ClustersResourceApi

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

the class ClouderaManagerModificationService method callPostClouderaRuntimeUpgradeCommandIfCMIsNewerThan751.

private void callPostClouderaRuntimeUpgradeCommandIfCMIsNewerThan751(ClustersResourceApi clustersResourceApi) throws ApiException, CloudbreakException {
    ClouderaManagerRepo clouderaManagerRepo = clusterComponentConfigProvider.getClouderaManagerRepoDetails(stack.getCluster().getId());
    String currentCMVersion = clouderaManagerRepo.getVersion();
    Versioned baseCMVersion = CLOUDERAMANAGER_VERSION_7_5_1;
    if (isVersionNewerOrEqualThanLimited(currentCMVersion, baseCMVersion)) {
        LOGGER.debug("Cloudera Manager version {} is newer than {} hence calling post runtime upgrade command using /v45 API", currentCMVersion, baseCMVersion.getVersion());
        eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), ResourceEvent.CLUSTER_UPGRADE_START_POST_UPGRADE);
        waitForRestartCommandIfThereIsAny(clustersResourceApi);
        Cluster cluster = stack.getCluster();
        String user = cluster.getCloudbreakAmbariUser();
        String password = cluster.getCloudbreakAmbariPassword();
        try {
            ApiClient v45Client = clouderaManagerApiClientProvider.getV45Client(stack.getGatewayPort(), user, password, clientConfig);
            ClustersResourceApi clustersResourceV45Api = clouderaManagerApiFactory.getClustersResourceApi(v45Client);
            clouderaManagerUpgradeService.callPostRuntimeUpgradeCommand(clustersResourceV45Api, stack, v45Client);
        } catch (ClouderaManagerClientInitException e) {
            LOGGER.info("Couldn't build CM v45 client", e);
            throw new CloudbreakException(e);
        }
    } else {
        LOGGER.debug("Cloudera Manager version {} is older than {} hence NOT calling post runtime upgrade command", currentCMVersion, baseCMVersion.getVersion());
    }
}
Also used : ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi)

Example 7 with ClustersResourceApi

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

the class ClouderaManagerDecomissioner method deleteHostFromClouderaManager.

private void deleteHostFromClouderaManager(Stack stack, InstanceMetaData data, ApiClient client) {
    HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
    try {
        ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
        Optional<ApiHost> hostRefOptional = hostRefList.getItems().stream().filter(host -> data.getDiscoveryFQDN() != null && data.getDiscoveryFQDN().equals(host.getHostname())).findFirst();
        if (hostRefOptional.isPresent()) {
            ApiHost hostRef = hostRefOptional.get();
            ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
            clustersResourceApi.removeHost(stack.getName(), hostRef.getHostId());
            hostsResourceApi.deleteHost(hostRef.getHostId());
            LOGGER.debug("Host remove request sent. Host id: [{}]", hostRef.getHostId());
        } else {
            LOGGER.debug("Host already deleted.");
        }
    } catch (ApiException e) {
        LOGGER.error("Failed to delete host: {}", data.getDiscoveryFQDN(), e);
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiException(com.cloudera.api.swagger.client.ApiException) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) FlowMessageService(com.sequenceiq.cloudbreak.message.FlowMessageService) Map(java.util.Map) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) NotEnoughNodeException(com.sequenceiq.cloudbreak.cluster.service.NotEnoughNodeException) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiHostsToRemoveArgs(com.cloudera.api.swagger.model.ApiHostsToRemoveArgs) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiHostNameList(com.cloudera.api.swagger.model.ApiHostNameList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) HostServiceStatuses(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatuses) HostServiceStatus(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) Function(java.util.function.Function) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ApiHost(com.cloudera.api.swagger.model.ApiHost) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Consumer(java.util.function.Consumer) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Component(org.springframework.stereotype.Component) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CommandsResourceApi(com.cloudera.api.swagger.CommandsResourceApi) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) Comparator(java.util.Comparator) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) StringUtils(org.springframework.util.StringUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 8 with ClustersResourceApi

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

the class ClouderaManagerKerberosService method configureKerberosViaApi.

public void configureKerberosViaApi(ApiClient client, HttpClientConfig clientConfig, Stack stack, KerberosConfig kerberosConfig) throws ApiException, CloudbreakException {
    Cluster cluster = stack.getCluster();
    if (kerberosDetailService.isAdJoinable(kerberosConfig) || kerberosDetailService.isIpaJoinable(kerberosConfig)) {
        ClouderaManagerModificationService modificationService = applicationContext.getBean(ClouderaManagerModificationService.class, stack, clientConfig);
        ClouderaManagerResourceApi clouderaManagerResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
        modificationService.stopCluster(false);
        ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
        ApiCommand configureForKerberos = clustersResourceApi.configureForKerberos(cluster.getName(), new ApiConfigureForKerberosArguments());
        clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, configureForKerberos.getId());
        ApiCommand generateCredentials = clouderaManagerResourceApi.generateCredentialsCommand();
        clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, generateCredentials.getId());
        List<ApiCommand> commands = clustersResourceApi.listActiveCommands(stack.getName(), SUMMARY).getItems();
        BigDecimal deployClusterConfigId = clouderaManagerCommonCommandService.getDeployClientConfigCommandId(stack, clustersResourceApi, commands);
        clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, deployClusterConfigId);
        modificationService.startCluster();
    }
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiConfigureForKerberosArguments(com.cloudera.api.swagger.model.ApiConfigureForKerberosArguments) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal)

Example 9 with ClustersResourceApi

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

the class ClouderaManagerClusterStatusService method findCommand.

@Override
public Optional<ClusterManagerCommand> findCommand(Stack stack, ClusterCommandType command) {
    try {
        ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
        ClouderaManagerCommand clouderaManagerCommand = ClouderaManagerCommand.ofType(command);
        if (clouderaManagerCommand == null) {
            return Optional.empty();
        }
        Optional<BigDecimal> commandId = syncApiCommandRetriever.getCommandId(clouderaManagerCommand.getName(), clustersResourceApi, stack);
        if (commandId.isPresent()) {
            return Optional.ofNullable(convertApiCommand(clouderaManagerCommandsService.getApiCommand(client, commandId.get())));
        } else {
            LOGGER.info("Command {} could not been found in CM for stack {}", command, stack.getName());
            return Optional.empty();
        }
    } catch (CloudbreakException | ApiException e) {
        LOGGER.warn("Unexpected error during CM command table fetching, assuming no such command exists", e);
        return Optional.empty();
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 10 with ClustersResourceApi

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

the class ClouderaManagerSetupServiceTest method testInstallClusterWhenApiExceptionOccursShouldReturnClouderaManagerOperationFailedException.

@Test
public void testInstallClusterWhenApiExceptionOccursShouldReturnClouderaManagerOperationFailedException() throws ApiException {
    ClustersResourceApi clustersResourceApi = mock(ClustersResourceApi.class);
    ApiException error = mock(ApiException.class);
    when(error.getResponseBody()).thenReturn(null);
    when(error.getMessage()).thenReturn("error");
    when(clouderaManagerApiFactory.getClustersResourceApi(any(ApiClient.class))).thenReturn(clustersResourceApi);
    doThrow(error).when(clustersResourceApi).readCluster(anyString());
    ClouderaManagerOperationFailedException actual = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.installCluster(""));
    assertEquals(ClouderaManagerOperationFailedException.class, actual.getClass());
}
Also used : ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException) Test(org.junit.jupiter.api.Test)

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