Search in sources :

Example 6 with ClouderaManagerClientInitException

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

the class ClouderaManagerSecurityService method changeOriginalCredentialsAndCreateCloudbreakUser.

@Override
public void changeOriginalCredentialsAndCreateCloudbreakUser(boolean ldapConfigured) throws CloudbreakException {
    LOGGER.debug("change original admin user and create cloudbreak user");
    try {
        ApiClient client = createApiClient();
        UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
        ApiUser2List userList = usersResourceApi.readUsers2("SUMMARY");
        ApiUser2 oldAdminUser = getOldAdminUser(userList).orElseThrow(() -> new CloudbreakException("Can't find original admin user"));
        Cluster cluster = stack.getCluster();
        createNewUser(usersResourceApi, oldAdminUser.getAuthRoles(), cluster.getCloudbreakAmbariUser(), cluster.getCloudbreakAmbariPassword(), userList);
        createNewUser(usersResourceApi, oldAdminUser.getAuthRoles(), cluster.getDpAmbariUser(), cluster.getDpAmbariPassword(), userList);
        if (ADMIN_USER.equals(cluster.getUserName())) {
            oldAdminUser.setPassword(cluster.getPassword());
            usersResourceApi.updateUser2(oldAdminUser.getName(), oldAdminUser);
        } else if (cluster.getUserName() != null) {
            createUserSuppliedCMUser(userList, oldAdminUser, cluster);
        }
        removeDefaultAdminUser(ldapConfigured, Optional.ofNullable(cluster.getUserName()));
    } catch (ApiException | ClusterClientInitException | 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) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) 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 7 with ClouderaManagerClientInitException

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

the class ClouderaManagerSetupService method waitForHosts.

@Override
public ExtendedPollingResult waitForHosts(Set<InstanceMetaData> hostsInCluster) throws ClusterClientInitException {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    ApiClient client;
    try {
        client = clouderaManagerApiClientProvider.getV31Client(stack.getGatewayPort(), user, password, clientConfig);
    } catch (ClouderaManagerClientInitException e) {
        throw new ClusterClientInitException(e);
    }
    List<String> privateIps = hostsInCluster.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
    return clouderaManagerPollingServiceProvider.startPollingCmHostStatus(stack, client, privateIps);
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ApiCluster(com.cloudera.api.swagger.model.ApiCluster) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient)

Example 8 with ClouderaManagerClientInitException

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

the class ClouderaManagerSetupService method createApiClient.

private ApiClient createApiClient() throws ClusterClientInitException {
    ApiClient client = null;
    try {
        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) {
        return returnClientBasedOnApiError(client, e);
    }
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) 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)

Example 9 with ClouderaManagerClientInitException

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

the class ClouderaManagerSetupServiceTest method testWaitForHostsWhenDropClouderaManagerClientInitExceptionShouldReturnClusterClientInitException.

@Test
public void testWaitForHostsWhenDropClouderaManagerClientInitExceptionShouldReturnClusterClientInitException() throws Exception {
    doThrow(new ClouderaManagerClientInitException()).when(clouderaManagerApiClientProvider).getV31Client(anyInt(), anyString(), anyString(), any(HttpClientConfig.class));
    ClusterClientInitException actual = assertThrows(ClusterClientInitException.class, () -> underTest.waitForHosts(Set.of()));
    assertEquals(ClusterClientInitException.class, actual.getClass());
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) Test(org.junit.jupiter.api.Test)

Example 10 with ClouderaManagerClientInitException

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

the class ClouderaManagerModificationService method initApiClient.

@PostConstruct
public void initApiClient() throws ClusterClientInitException {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        apiClient = clouderaManagerApiClientProvider.getV31Client(stack.getGatewayPort(), user, password, 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)

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