Search in sources :

Example 61 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariUserHandlerTest method testCreateAmbariUserWhenExceptionOccuredThenTryingToCreateNewClientAndGetAmbariVersionAndThrowExceptionThenShouldThrowCloudbreakException.

@Test
public void testCreateAmbariUserWhenExceptionOccuredThenTryingToCreateNewClientAndGetAmbariVersionAndThrowExceptionThenShouldThrowCloudbreakException() throws CloudbreakException {
    String newUserName = "newUserName";
    String newPassword = "newPassword";
    Stack stack = TestUtil.stack();
    AmbariClient ambariClient = mock(AmbariClient.class);
    when(ambariClient.createUser(newUserName, newPassword, true)).thenThrow(new AmbariServiceException("failed"));
    when(ambariClient.ambariServerVersion()).thenReturn("2.4");
    when(ambariClientFactory.getAmbariClient(stack, newUserName, newPassword)).thenThrow(new AmbariServiceException("failed"));
    thrown.expect(CloudbreakException.class);
    thrown.expectMessage("failed");
    AmbariClient ambariClientResult = underTest.createAmbariUser(newUserName, newPassword, stack, ambariClient);
    Assert.assertEquals(ambariClient, ambariClientResult);
    verify(ambariClient, times(1)).createUser(newUserName, newPassword, true);
    verify(ambariClientFactory, times(1)).getAmbariClient(stack, newUserName, newPassword);
    verify(ambariClient, times(0)).ambariServerVersion();
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 62 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariDecommissionerTest method testVerifyNodeCountWithValidationException.

@Test
public void testVerifyNodeCountWithValidationException() throws CloudbreakSecuritySetupException {
    thrown.expect(NotEnoughNodeException.class);
    String hostGroupName = "hostGroupName";
    String hostname = "hostname";
    String ipAddress = "192.18.256.1";
    int gatewayPort = 1234;
    String ambariName = "ambari-name";
    Map<String, List<String>> blueprintMap = new HashMap<>();
    blueprintMap.put(hostGroupName, Collections.singletonList("DATANODE"));
    Blueprint blueprint = new Blueprint();
    blueprint.setName(ambariName);
    blueprint.setAmbariName(ambariName);
    Cluster cluster = new Cluster();
    cluster.setAmbariIp(ipAddress);
    cluster.setBlueprint(blueprint);
    Stack stack = new Stack();
    stack.setGatewayPort(gatewayPort);
    stack.setId(100L);
    HostGroup hostGroup = new HostGroup();
    hostGroup.setName(hostGroupName);
    hostGroup.setHostMetadata(Collections.singleton(getHostMetadata(0L)));
    AmbariClient ambariClient = mock(AmbariClient.class);
    HttpClientConfig config = new HttpClientConfig(ipAddress);
    when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp())).thenReturn(config);
    when(ambariClientProvider.getAmbariClient(config, stack.getGatewayPort(), cluster)).thenReturn(ambariClient);
    when(hostGroupService.getByClusterAndHostName(cluster, hostname)).thenReturn(hostGroup);
    when(ambariClient.getBlueprintMap(ambariName)).thenReturn(blueprintMap);
    when(configurationService.getConfiguration(ambariClient, hostGroupName)).thenReturn(Collections.singletonMap(ConfigParam.DFS_REPLICATION.key(), "3"));
    thrown.expect(NotEnoughNodeException.class);
    thrown.expectMessage("There is not enough node to downscale. Check the replication factor and the ApplicationMaster occupation.");
    underTest.verifyNodeCount(stack, cluster, hostname);
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) List(java.util.List) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 63 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class CloudbreakUtil method checkClusterAvailability.

private static void checkClusterAvailability(StackResponse stackResponse, String port, String stackId, String ambariUser, String ambariPassowrd, boolean checkAmbari) {
    Assert.assertEquals(stackResponse.getCluster().getStatus(), Status.AVAILABLE, "The cluster hasn't been started!");
    Assert.assertEquals(stackResponse.getStatus(), Status.AVAILABLE, "The stack hasn't been started!");
    String ambariIp = stackResponse.getCluster().getAmbariServerIp();
    Assert.assertNotNull(ambariIp, "The Ambari IP is not available!");
    if (checkAmbari) {
        AmbariClient ambariClient = new AmbariClient(ambariIp, port, ambariUser, ambariPassowrd);
        Assert.assertEquals(ambariClient.healthCheck(), "RUNNING", "The Ambari server is not running!");
        Assert.assertEquals(ambariClient.getClusterHosts().size(), getNodeCount(stackResponse), "The number of cluster nodes in the stack differs from the number of nodes registered in ambari");
    }
}
Also used : AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 64 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class CloudbreakUtil method checkClusterStopped.

private static void checkClusterStopped(String port, String ambariUser, String ambariPassword, StackResponse stackResponse) {
    Assert.assertEquals(stackResponse.getCluster().getStatus(), Status.STOPPED, "The cluster is not stopped!");
    Assert.assertEquals(stackResponse.getStatus(), Status.STOPPED, "The stack is not stopped!");
    String ambariIp = stackResponse.getCluster().getAmbariServerIp();
    AmbariClient ambariClient = new AmbariClient(ambariIp, port, ambariUser, ambariPassword);
    Assert.assertFalse(isAmbariRunning(ambariClient), "The Ambari server is running in stopped state!");
}
Also used : AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 65 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterService method retrieveOutputs.

@Override
public ConfigsResponse retrieveOutputs(Long stackId, Set<BlueprintParameterJson> requests) throws IOException {
    Stack stack = stackService.get(stackId);
    AmbariClient ambariClient = getAmbariClient(stack);
    Cluster cluster = stack.getCluster();
    List<String> targets = new ArrayList<>();
    Map<String, String> bpI = new HashMap<>();
    if (cluster.getBlueprintInputs().getValue() != null) {
        bpI = cluster.getBlueprintInputs().get(Map.class);
    }
    prepareTargets(requests, targets, bpI);
    Map<String, String> results = new HashMap<>();
    if (cluster.getAmbariIp() != null) {
        results = ambariClient.getConfigValuesByConfigIds(targets);
    }
    prepareResults(requests, cluster, bpI, results);
    prepareAdditionalInputParameters(results, cluster);
    Set<BlueprintInputJson> blueprintInputJsons = new HashSet<>();
    for (Entry<String, String> stringStringEntry : results.entrySet()) {
        for (BlueprintParameterJson blueprintParameter : requests) {
            if (stringStringEntry.getKey().equals(blueprintParameter.getName())) {
                BlueprintInputJson blueprintInputJson = new BlueprintInputJson();
                blueprintInputJson.setName(blueprintParameter.getName());
                blueprintInputJson.setPropertyValue(stringStringEntry.getValue());
                blueprintInputJsons.add(blueprintInputJson);
                break;
            }
        }
    }
    ConfigsResponse configsResponse = new ConfigsResponse();
    configsResponse.setInputs(blueprintInputJsons);
    return configsResponse;
}
Also used : HashMap(java.util.HashMap) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) ArrayList(java.util.ArrayList) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) Map(java.util.Map) HashMap(java.util.HashMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HashSet(java.util.HashSet) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)

Aggregations

AmbariClient (com.sequenceiq.ambari.client.AmbariClient)78 Test (org.junit.Test)39 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)37 Stack (com.sequenceiq.cloudbreak.domain.Stack)32 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)23 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)16 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)16 HashMap (java.util.HashMap)16 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)14 Matchers.anyString (org.mockito.Matchers.anyString)14 Map (java.util.Map)13 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)10 Collections.singletonMap (java.util.Collections.singletonMap)9 HashSet (java.util.HashSet)9 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)6 Status (com.sequenceiq.cloudbreak.api.model.Status)6 List (java.util.List)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6