Search in sources :

Example 56 with AmbariClient

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

the class AmbariClusterSetupServiceTest method testApiAvailableWhenPollerReturnFalseThenApiShouldBeNotAvailable.

@Test
public void testApiAvailableWhenPollerReturnFalseThenApiShouldBeNotAvailable() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = ambariClient();
    when(ambariPollingServiceProvider.isAmbariAvailable(stack, ambariClient)).thenReturn(false);
    when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
    boolean available = underTest.available(stack);
    verify(ambariPollingServiceProvider, times(1)).isAmbariAvailable(stack, ambariClient);
    verify(clientFactory, times(1)).getAmbariClient(stack, stack.getCluster());
    Assert.assertFalse(available);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 57 with AmbariClient

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

the class AmbariHostsWithNamesTest method testAmbariHostsWithNames.

@Test
public void testAmbariHostsWithNames() {
    Stack stack = TestUtil.stack();
    List<String> hostNames = Lists.newArrayList("hostname1", "hostname2");
    AmbariClient ambariClient = mock(AmbariClient.class);
    AmbariHostsWithNames ambariHostsWithNames = new AmbariHostsWithNames(stack, ambariClient, hostNames);
    Assert.assertEquals(stack, ambariHostsWithNames.getStack());
    Assert.assertEquals(hostNames, ambariHostsWithNames.getHostNames());
    Assert.assertEquals(ambariClient, ambariHostsWithNames.getAmbariClient());
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 58 with AmbariClient

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

the class AmbariSmartSenseCapturerTest method testCaptureWheTriggerNeedsToBeDoneAndNoExceptionOccured.

@Test
public void testCaptureWheTriggerNeedsToBeDoneAndNoExceptionOccured() {
    Optional<SmartSenseSubscription> smartSenseSubscription = Optional.empty();
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(ambariClient.smartSenseCapture(1)).thenReturn(1);
    when(smartSenseSubscriptionService.getDefault()).thenReturn(smartSenseSubscription);
    when(smartsenseConfigurationLocator.smartsenseConfigurable(smartSenseSubscription)).thenReturn(true);
    underTest.capture(1, ambariClient);
    verify(ambariClient, times(1)).smartSenseCapture(anyInt());
}
Also used : SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 59 with AmbariClient

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

the class AmbariSmartSenseCapturerTest method testCaptureWheTriggerNeedsToBeDoneAndExceptionOccured.

@Test
public void testCaptureWheTriggerNeedsToBeDoneAndExceptionOccured() {
    Optional<SmartSenseSubscription> smartSenseSubscription = Optional.empty();
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(ambariClient.smartSenseCapture(1)).thenThrow(new AmbariServiceException("failed"));
    when(smartSenseSubscriptionService.getDefault()).thenReturn(smartSenseSubscription);
    when(smartsenseConfigurationLocator.smartsenseConfigurable(smartSenseSubscription)).thenReturn(true);
    underTest.capture(1, ambariClient);
    verify(ambariClient, times(1)).smartSenseCapture(anyInt());
}
Also used : SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 60 with AmbariClient

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

the class AmbariUserHandlerTest method testCreateAmbariUserWhenExceptionOccuredThenTryingToCreateNewAmbariClientAndQueryAmbariVersion.

@Test
public void testCreateAmbariUserWhenExceptionOccuredThenTryingToCreateNewAmbariClientAndQueryAmbariVersion() 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", new AmbariOperationFailedException("failed")));
    when(ambariClient.ambariServerVersion()).thenReturn("2.4");
    when(ambariClientFactory.getAmbariClient(stack, newUserName, newPassword)).thenReturn(ambariClient);
    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(1)).ambariServerVersion();
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

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