use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.
the class AmbariClusterServiceTest method setup.
@Before
public void setup() throws CloudbreakException {
Cluster cluster = new Cluster();
cluster.setId(1L);
cluster.setBlueprint(new Blueprint());
cluster.getBlueprint().setId(1L);
Stack stack = new Stack();
stack.setOrchestrator(new Orchestrator());
stack.setCluster(cluster);
when(clusterRepository.findById(any(Long.class))).thenReturn(cluster);
when(stackService.getByIdWithLists(any(Long.class))).thenReturn(stack);
when(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).thenReturn(OrchestratorType.HOST);
when(orchestratorTypeResolver.resolveType(anyString())).thenReturn(OrchestratorType.HOST);
when(clusterComponentConfigProvider.getHDPRepo(any(Long.class))).thenReturn(new StackRepoDetails());
when(clusterComponentConfigProvider.store(any(ClusterComponent.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, ClusterComponent.class));
when(clusterComponentConfigProvider.getComponent(any(Long.class), any(ComponentType.class))).thenReturn(new ClusterComponent());
when(blueprintService.get(any(Long.class))).thenReturn(cluster.getBlueprint());
}
use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.
the class AmbariClientFactoryTest method testGetAmbariClientWithUsernameAndPasswordWhenEverythingWorksFine.
@Test
public void testGetAmbariClientWithUsernameAndPasswordWhenEverythingWorksFine() throws CloudbreakSecuritySetupException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
stack.setCluster(cluster);
String userName = "userName";
String password = "password";
HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenReturn(httpClientConfig);
when(ambariClientProvider.getAmbariClient(httpClientConfig, stack.getGatewayPort(), userName, password)).thenReturn(ambariClient);
AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, userName, password);
Assert.assertEquals(ambariClient, defaultAmbariClient);
verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
verify(ambariClientProvider, times(1)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), userName, password);
}
use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.
the class AmbariClientFactoryTest method testGetAmbariClientWithUsernameAndPasswordWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.
@Test
public void testGetAmbariClientWithUsernameAndPasswordWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
String userName = "userName";
String password = "password";
stack.setCluster(cluster);
HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenThrow(new IllegalArgumentException("failed"));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("failed");
AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, userName, password);
Assert.assertEquals(ambariClient, defaultAmbariClient);
verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
verify(ambariClientProvider, times(0)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), userName, password);
}
use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.
the class AmbariClientFactoryTest method testGetAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.
@Test
public void testGetAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
stack.setCluster(cluster);
HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenThrow(new IllegalArgumentException("failed"));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("failed");
AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, cluster);
Assert.assertEquals(ambariClient, defaultAmbariClient);
verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
verify(ambariClientProvider, times(0)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), cluster);
}
use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testApiUpdateUserNamePasswordWhenChangePasswordThrowExceptionAndAmbariVersionThrowExceptionThenShouldThrowCloudbreakException.
@Test
public void testApiUpdateUserNamePasswordWhenChangePasswordThrowExceptionAndAmbariVersionThrowExceptionThenShouldThrowCloudbreakException() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
stack.setCluster(cluster);
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
String newPassword = "newadmin";
when(clusterService.getById(stack.getCluster().getId())).thenReturn(cluster);
when(clientFactory.getAmbariClient(stack, cluster.getUserName(), cluster.getPassword())).thenReturn(ambariClient);
when(clientFactory.getAmbariClient(stack, cluster.getUserName(), newPassword)).thenReturn(ambariClient);
when(ambariClient.changePassword(cluster.getUserName(), cluster.getPassword(), newPassword, true)).thenThrow(new AmbariConnectionException("test1"));
when(ambariClient.ambariServerVersion()).thenThrow(new AmbariConnectionException("test1"));
thrown.expect(CloudbreakException.class);
thrown.expectMessage("test1");
underTest.updateUserNamePassword(stack, newPassword);
verify(clientFactory, times(1)).getAmbariClient(stack, cluster.getUserName(), cluster.getPassword());
verify(clusterService, times(1)).getById(stack.getCluster().getId());
verify(ambariClient, times(1)).changePassword(cluster.getUserName(), cluster.getPassword(), newPassword, true);
verify(ambariClient, times(1)).ambariServerVersion();
}
Aggregations