Search in sources :

Example 11 with ClouderaManagerClientInitException

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

the class ClouderaManagerModificationService method buildv46ApiClient.

private ApiClient buildv46ApiClient() throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        return clouderaManagerApiClientProvider.getV46Client(stack.getGatewayPort(), user, password, clientConfig);
    } catch (ClouderaManagerClientInitException e) {
        LOGGER.error("Failed to init V46 client.", e);
        throw new CloudbreakException(e);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)

Example 12 with ClouderaManagerClientInitException

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

the class ClouderaManagerSecurityService method replaceUserNamePassword.

@Override
public void replaceUserNamePassword(String newUserName, String newPassword) 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);
        ApiUser2List oldUserList = usersResourceApi.readUsers2("SUMMARY");
        Optional<ApiUser2> oldAdminUser = oldUserList.getItems().stream().filter(apiUser2 -> apiUser2.getName().equals(stack.getCluster().getUserName())).findFirst();
        if (oldAdminUser.isPresent()) {
            createNewUser(usersResourceApi, oldAdminUser.get().getAuthRoles(), newUserName, newPassword, oldUserList);
            usersResourceApi.deleteUser2(oldAdminUser.get().getName());
        } else {
            throw new CloudbreakException("Can't find original admin user");
        }
    } catch (ApiException | ClouderaManagerClientInitException e) {
        LOGGER.info("Can't replace original admin user due to: ", e);
        throw new CloudbreakException("Can't replace original admin user 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) 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) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiUser2(com.cloudera.api.swagger.model.ApiUser2) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 13 with ClouderaManagerClientInitException

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

the class ClouderaManagerSecurityService method removeDefaultAdminUser.

private void removeDefaultAdminUser(boolean ldapConfigured, Optional<String> userName) {
    if (ldapConfigured && isUserIsNullOrNotAdmin(userName)) {
        try {
            String user = stack.getCluster().getCloudbreakAmbariUser();
            String password = stack.getCluster().getCloudbreakAmbariPassword();
            ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
            UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
            usersResourceApi.deleteUser2(ADMIN_USER);
        } catch (ApiException | ClouderaManagerClientInitException e) {
            LOGGER.info("Can't remove default admin user due to: ", e);
        }
    }
}
Also used : UsersResourceApi(com.cloudera.api.swagger.UsersResourceApi) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 14 with ClouderaManagerClientInitException

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

the class ClouderaManagerSecurityService method updateUserNamePassword.

@Override
public void updateUserNamePassword(String newPassword) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    String cmUser = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        ApiClient client = getClient(stack.getGatewayPort(), cmUser, password, clientConfig);
        UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
        ApiUser2List oldUserList = usersResourceApi.readUsers2("SUMMARY");
        Optional<ApiUser2> oldAdminUser = oldUserList.getItems().stream().filter(apiUser2 -> apiUser2.getName().equals(stack.getCluster().getUserName())).findFirst();
        if (oldAdminUser.isPresent()) {
            ApiUser2 user = oldAdminUser.get();
            user.setPassword(newPassword);
            usersResourceApi.updateUser2(user.getName(), user);
        } else {
            throw new CloudbreakException("Can't find admin user");
        }
    } catch (ApiException | ClouderaManagerClientInitException e) {
        LOGGER.info("Can't replace admin password due to: ", 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) 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) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiUser2(com.cloudera.api.swagger.model.ApiUser2) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 15 with ClouderaManagerClientInitException

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

the class ClouderaManagerSecurityService method rotateHostCertificates.

@Override
public void rotateHostCertificates(String sshUser, KeyPair sshKeyPair, String subAltName) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
        HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
        BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(client);
        ApiHostList hostList = hostsResourceApi.readHosts(null, null, "SUMMARY");
        ApiBatchRequest batchRequest = createHostCertsBatchRequest(hostList, sshUser, sshKeyPair, subAltName);
        ApiBatchResponse apiBatchResponse = batchResourceApi.execute(batchRequest);
        processHostCertsBatchResponse(client, apiBatchResponse);
    } catch (ApiException | ClouderaManagerClientInitException e) {
        LOGGER.warn("Can't rotate the host certificates", e);
        throw new CloudbreakException("Can't rotate the host certificates due to: " + e.getMessage());
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) 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) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) 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