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();
}
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);
}
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");
}
}
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!");
}
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;
}
Aggregations