Search in sources :

Example 1 with ClouderaManagerClientInitException

use of com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityService method setupMonitoringUser.

@Override
public void setupMonitoringUser() throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
        UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
        String monitoringUser = cluster.getCloudbreakClusterManagerMonitoringUser();
        String monitoringPassword = cluster.getCloudbreakClusterManagerMonitoringPassword();
        ApiUser2List userList = usersResourceApi.readUsers2("SUMMARY");
        Optional<ApiUser2> mUser = userList.getItems().stream().filter(apiUser2 -> apiUser2.getName().equals(monitoringUser)).findFirst();
        if (mUser.isPresent()) {
            LOGGER.info("Monitoring user '{}' already exists. Skipping user generation", monitoringUser);
        } else {
            List<ApiAuthRoleRef> authRoles = new ArrayList<>();
            ApiAuthRoleRef apiAuthRoleRef = new ApiAuthRoleRef();
            apiAuthRoleRef.setName("ROLE_ADMIN");
            authRoles.add(apiAuthRoleRef);
            createNewUser(usersResourceApi, authRoles, monitoringUser, monitoringPassword, userList);
        }
    } catch (ApiException | ClouderaManagerClientInitException e) {
        throw new CloudbreakException("Can't replace admin password due to: " + e.getMessage());
    }
}
Also used : UsersResourceApi(com.cloudera.api.swagger.UsersResourceApi) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) KeyPair(java.security.KeyPair) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) StringUtils(org.apache.commons.lang3.StringUtils) ApiAuthRoleRef(com.cloudera.api.swagger.model.ApiAuthRoleRef) Scope(org.springframework.context.annotation.Scope) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) UsersResourceApi(com.cloudera.api.swagger.UsersResourceApi) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Service(org.springframework.stereotype.Service) LdapView(com.sequenceiq.cloudbreak.dto.LdapView) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) Retryable(org.springframework.retry.annotation.Retryable) Logger(org.slf4j.Logger) VirtualGroupRequest(com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) URLUtils(com.sequenceiq.cloudbreak.util.URLUtils) ClusterSecurityService(com.sequenceiq.cloudbreak.cluster.api.ClusterSecurityService) ApiGenerateHostCertsArguments(com.cloudera.api.swagger.model.ApiGenerateHostCertsArguments) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ApiUser2(com.cloudera.api.swagger.model.ApiUser2) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) PkiUtil(com.sequenceiq.cloudbreak.certificate.PkiUtil) DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiAuthRoleRef(com.cloudera.api.swagger.model.ApiAuthRoleRef) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiUser2(com.cloudera.api.swagger.model.ApiUser2) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with ClouderaManagerClientInitException

use of com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException 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 3 with ClouderaManagerClientInitException

use of com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException in project cloudbreak by hortonworks.

the class ClouderaManagerDiagnosticsService method initApiClient.

@PostConstruct
public void initApiClient() throws ClusterClientInitException {
    Cluster cluster = stack.getCluster();
    String cloudbreakAmbariUser = cluster.getCloudbreakAmbariUser();
    String cloudbreakAmbariPassword = cluster.getCloudbreakAmbariPassword();
    try {
        client = clouderaManagerApiClientProvider.getV31Client(stack.getGatewayPort(), cloudbreakAmbariUser, cloudbreakAmbariPassword, clientConfig);
    } catch (ClouderaManagerClientInitException e) {
        throw new ClusterClientInitException(e);
    }
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) PostConstruct(javax.annotation.PostConstruct)

Example 4 with ClouderaManagerClientInitException

use of com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException in project cloudbreak by hortonworks.

the class ClouderaManagerKerberosService method deleteCredentials.

public void deleteCredentials(HttpClientConfig clientConfig, Stack stack) {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        ApiClient client = clouderaManagerApiClientProvider.getV31Client(stack.getGatewayPort(), user, password, clientConfig);
        clouderaManagerConfigService.disableKnoxAutorestartIfCmVersionAtLeast(CLOUDERAMANAGER_VERSION_7_1_0, client, stack.getName());
        ClouderaManagerModificationService modificationService = applicationContext.getBean(ClouderaManagerModificationService.class, stack, clientConfig);
        modificationService.stopCluster(false);
        ClouderaManagerClusterDecommissionService decomissionService = applicationContext.getBean(ClouderaManagerClusterDecommissionService.class, stack, clientConfig);
        decomissionService.removeManagementServices();
        ClouderaManagerResourceApi apiInstance = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
        ApiCommand command = apiInstance.deleteCredentialsCommand("all");
        clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, command.getId());
    } catch (ApiException | CloudbreakException | ClouderaManagerClientInitException e) {
        LOGGER.info("Failed to remove Kerberos credentials", e);
        throw new ClouderaManagerOperationFailedException("Failed to remove Kerberos credentials", e);
    }
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) 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) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 5 with ClouderaManagerClientInitException

use of com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityService method createApiClient.

private ApiClient createApiClient() throws ClusterClientInitException, ClouderaManagerClientInitException, CloudbreakException {
    try {
        ApiClient client = clouderaManagerApiClientProvider.getDefaultClient(stack.getGatewayPort(), clientConfig, ClouderaManagerApiClientProvider.API_V_31);
        ToolsResourceApi toolsResourceApi = clouderaManagerApiFactory.getToolsResourceApi(client);
        toolsResourceApi.echo("TEST");
        LOGGER.debug("Cloudera Manager already running, old admin user's password has not been changed yet.");
        return client;
    } catch (ClouderaManagerClientInitException e) {
        throw new ClusterClientInitException(e);
    } catch (ApiException e) {
        if (org.springframework.http.HttpStatus.UNAUTHORIZED.value() == e.getCode()) {
            return createClientWithNewPassword();
        }
        LOGGER.debug("Cloudera Manager is not running.", e);
        throw new CloudbreakException("Cloudera Manager is not running. " + e.getMessage());
    }
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)22 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 ClusterClientInitException (com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException)15 ApiClient (com.cloudera.api.swagger.client.ApiClient)14 ApiException (com.cloudera.api.swagger.client.ApiException)11 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)9 ToolsResourceApi (com.cloudera.api.swagger.ToolsResourceApi)5 UsersResourceApi (com.cloudera.api.swagger.UsersResourceApi)5 ApiCluster (com.cloudera.api.swagger.model.ApiCluster)5 PostConstruct (javax.annotation.PostConstruct)5 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)4 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)4 ApiBatchRequest (com.cloudera.api.swagger.model.ApiBatchRequest)4 ApiBatchResponse (com.cloudera.api.swagger.model.ApiBatchResponse)4 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)4 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)4 ApiUser2 (com.cloudera.api.swagger.model.ApiUser2)4 ApiUser2List (com.cloudera.api.swagger.model.ApiUser2List)4 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)4 ApiAuthRoleRef (com.cloudera.api.swagger.model.ApiAuthRoleRef)3