use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class StackScalingServiceTest method shouldRemoveHostMetadataUsingId.
@Test
public void shouldRemoveHostMetadataUsingId() {
Stack stack = mock(Stack.class);
when(stack.getId()).thenReturn(123L);
InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
when(instanceMetaData.getInstanceId()).thenReturn("i-1234567");
HostMetadata hostMetadata = mock(HostMetadata.class);
when(hostMetadata.getId()).thenReturn(456L);
stackScalingService.removeHostmetadataIfExists(stack, instanceMetaData, hostMetadata);
verify(hostMetadataRepository).delete(456L);
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class StackRepairServiceTest method setupHostMetadata.
private void setupHostMetadata(Long clusterId, String privateIp, String hostGroupName) {
HostMetadata hmd1 = mock(HostMetadata.class);
HostGroup hg1 = mock(HostGroup.class);
when(hg1.getName()).thenReturn(hostGroupName);
when(hmd1.getHostGroup()).thenReturn(hg1);
when(hostMetadataRepository.findHostInClusterByName(clusterId, privateIp)).thenReturn(hmd1);
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterCreationSuccessHandler method handleClusterCreationSuccess.
public void handleClusterCreationSuccess(Stack stack, Cluster cluster) {
LOGGER.info("Cluster created successfully. Cluster name: {}", cluster.getName());
Long now = new Date().getTime();
cluster.setCreationFinished(now);
cluster.setUpSince(now);
cluster = clusterService.updateCluster(cluster);
Collection<InstanceMetaData> updatedInstances = new ArrayList<>();
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
Set<InstanceMetaData> instances = instanceGroup.getAllInstanceMetaData();
for (InstanceMetaData instanceMetaData : instances) {
if (!instanceMetaData.isTerminated()) {
instanceMetaData.setInstanceStatus(InstanceStatus.REGISTERED);
updatedInstances.add(instanceMetaData);
}
}
}
instanceMetadataRepository.save(updatedInstances);
Collection<HostMetadata> hostMetadata = new ArrayList<>();
for (HostMetadata host : hostMetadataRepository.findHostsInCluster(cluster.getId())) {
host.setHostMetadataState(HostMetadataState.HEALTHY);
hostMetadata.add(host);
}
hostMetadataRepository.save(hostMetadata);
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterModificationService method upscaleCluster.
@Override
public void upscaleCluster(Stack stack, HostGroup hostGroup, Collection<HostMetadata> hostMetadata) throws CloudbreakException {
AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
List<String> upscaleHostNames = hostMetadata.stream().map(HostMetadata::getHostName).collect(Collectors.toList()).stream().filter(hostName -> !ambariClient.getClusterHosts().contains(hostName)).collect(Collectors.toList());
if (!upscaleHostNames.isEmpty()) {
recipeEngine.executePostAmbariStartRecipes(stack, Sets.newHashSet(hostGroup));
Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperations(stack, ambariClient, installServices(upscaleHostNames, stack, ambariClient, hostGroup.getName()), UPSCALE_AMBARI_PROGRESS_STATE);
String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_UPSCALE_FAILED.code()) : pollingResult.getRight().getMessage();
ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
}
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterSetupService method buildCluster.
@Override
public void buildCluster(Stack stack) {
Cluster cluster = stack.getCluster();
try {
clusterService.updateCreationDateOnCluster(cluster);
AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
BlueprintPreparationObject blueprintPreparationObject = conversionService.convert(stack, BlueprintPreparationObject.class);
Map<String, List<Map<String, String>>> hostGroupMappings = hostGroupAssociationBuilder.buildHostGroupAssociations(hostGroups);
Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(cluster.getId());
recipeEngine.executePostAmbariStartRecipes(stack, hostGroups);
ambariRepositoryVersionService.setBaseRepoURL(stack.getName(), cluster.getId(), stack.getOrchestrator(), ambariClient);
String blueprintText = centralBlueprintUpdater.getBlueprintText(blueprintPreparationObject);
addBlueprint(stack.getId(), ambariClient, blueprintText, cluster.getTopologyValidation());
cluster.setExtendedBlueprintText(blueprintText);
clusterService.updateCluster(cluster);
PollingResult waitForHostsResult = ambariPollingServiceProvider.hostsPollingService(stack, ambariClient, hostsInCluster);
ambariClusterConnectorPollingResultChecker.checkPollingResult(waitForHostsResult, cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
ambariClusterTemplateService.addClusterTemplate(cluster, hostGroupMappings, ambariClient);
Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperationsToStart(stack, ambariClient, singletonMap("INSTALL_START", 1), START_OPERATION_STATE);
String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
Pair<PollingResult, Exception> pollingResultExceptionPair = ambariOperationService.waitForOperations(stack, ambariClient, new HashMap<String, Integer>() {
{
put("CLUSTER_INSTALL", 1);
}
}, INSTALL_AMBARI_PROGRESS_STATE);
ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResultExceptionPair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()));
recipeEngine.executePostInstall(stack);
ambariSmartSenseCapturer.capture(0, ambariClient);
cluster = ambariViewProvider.provideViewInformation(ambariClient, cluster);
ambariClusterCreationSuccessHandler.handleClusterCreationSuccess(stack, cluster);
} catch (CancellationException cancellationException) {
throw cancellationException;
} catch (HttpResponseException hre) {
throw new AmbariOperationFailedException("Ambari could not create the cluster: " + AmbariClientExceptionUtil.getErrorMessage(hre), hre);
} catch (Exception e) {
LOGGER.error("Error while building the Ambari cluster. Message {}, throwable: {}", e.getMessage(), e);
throw new AmbariOperationFailedException(e.getMessage(), e);
}
}
Aggregations