use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class StackSyncService method updateMetaDataToRunning.
private void updateMetaDataToRunning(Long stackId, Cluster cluster, InstanceMetaData instanceMetaData) {
InstanceGroup instanceGroup = instanceMetaData.getInstanceGroup();
if (InstanceStatus.TERMINATED.equals(instanceMetaData.getInstanceStatus())) {
instanceGroup.setNodeCount(instanceGroup.getNodeCount() + 1);
}
HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(cluster.getId(), instanceMetaData.getDiscoveryFQDN());
if (hostMetadata != null) {
LOGGER.info("Instance '{}' was found in the cluster metadata, setting it's state to REGISTERED.", instanceMetaData.getInstanceId());
instanceMetaData.setInstanceStatus(InstanceStatus.REGISTERED);
} else {
LOGGER.info("Instance '{}' was not found in the cluster metadata, setting it's state to UNREGISTERED.", instanceMetaData.getInstanceId());
instanceMetaData.setInstanceStatus(InstanceStatus.UNREGISTERED);
}
instanceMetaDataRepository.save(instanceMetaData);
instanceGroupRepository.save(instanceGroup);
eventService.fireCloudbreakEvent(stackId, AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_UPDATED.code(), Arrays.asList(instanceMetaData.getDiscoveryFQDN(), "running")));
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class StackSyncService method deleteHostFromCluster.
private void deleteHostFromCluster(Stack stack, InstanceMetaData instanceMetaData) {
try {
if (stack.getCluster() != null) {
HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
if (hostMetadata == null) {
if (instanceMetaData.getInstanceStatus() != InstanceStatus.TERMINATED) {
throw new NotFoundException(String.format("Host not found with id '%s'", instanceMetaData.getDiscoveryFQDN()));
}
} else {
if (ambariClusterConnector.available(stack)) {
if (ambariDecommissioner.deleteHostFromAmbari(stack, hostMetadata)) {
hostMetadataRepository.delete(hostMetadata.getId());
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_HOST_DELETED.code(), Collections.singletonList(instanceMetaData.getDiscoveryFQDN())));
} else {
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_REMOVAL_FAILED.code(), Collections.singletonList(instanceMetaData.getDiscoveryFQDN())));
}
} else {
hostMetadata.setHostMetadataState(HostMetadataState.UNHEALTHY);
hostMetadataRepository.save(hostMetadata);
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_HOST_UPDATED.code(), Arrays.asList(instanceMetaData.getDiscoveryFQDN(), HostMetadataState.UNHEALTHY.name())));
}
}
}
} catch (Exception e) {
LOGGER.error("Host cannot be deleted from cluster: ", e);
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_TERMINATED.code(), Collections.singletonList(instanceMetaData.getDiscoveryFQDN())));
}
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class InstanceTerminationService method finishInstanceTermination.
public void finishInstanceTermination(InstanceTerminationContext context, RemoveInstanceResult payload) {
Stack stack = context.getStack();
List<InstanceMetaData> instanceMetaDataList = context.getInstanceMetaDataList();
for (InstanceMetaData instanceMetaData : instanceMetaDataList) {
String instanceId = instanceMetaData.getInstanceId();
InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupId(instanceMetaData.getInstanceGroup().getId());
stackScalingService.updateRemovedResourcesState(stack, Collections.singleton(instanceId), instanceGroup);
if (stack.getCluster() != null) {
HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
if (hostMetadata != null) {
LOGGER.info("Remove obsolete host: {}", hostMetadata.getHostName());
stackScalingService.removeHostmetadataIfExists(stack, instanceMetaData, hostMetadata);
}
}
}
LOGGER.info("Terminate instance result: {}", payload);
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.AVAILABLE, "Instance removed");
flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_REMOVING_INSTANCE_FINISHED, AVAILABLE.name());
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class ClusterUpscaleFlowService method updateFailedHostMetaData.
private void updateFailedHostMetaData(Collection<String> successHosts, Iterable<HostMetadata> hostMetadata) {
for (HostMetadata metaData : hostMetadata) {
if (!successHosts.contains(metaData.getHostName())) {
metaData.setHostMetadataState(HostMetadataState.UNHEALTHY);
hostMetadataRepository.save(metaData);
}
}
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class ClusterUpscaleFlowService method updateMetadata.
private int updateMetadata(StackView stackView, String hostGroupName) {
LOGGER.info("Start update metadata");
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stackView.getClusterView().getId(), hostGroupName);
Set<HostMetadata> hostMetadata = hostGroupService.findEmptyHostMetadataInHostGroup(hostGroup.getId());
updateFailedHostMetaData(hostMetadata);
int failedHosts = 0;
for (HostMetadata hostMeta : hostMetadata) {
if (hostGroup.getConstraint().getInstanceGroup() != null) {
stackService.updateMetaDataStatus(stackView.getId(), hostMeta.getHostName(), InstanceStatus.REGISTERED);
}
hostGroupService.updateHostMetaDataStatus(hostMeta.getId(), HostMetadataState.HEALTHY);
if (hostMeta.getHostMetadataState() == HostMetadataState.UNHEALTHY) {
failedHosts++;
}
}
return failedHosts;
}
Aggregations