Search in sources :

Example 16 with HostMetadata

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")));
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 17 with HostMetadata

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())));
    }
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 18 with HostMetadata

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());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 19 with HostMetadata

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);
        }
    }
}
Also used : HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 20 with HostMetadata

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;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)52 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)20 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)17 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)16 HashSet (java.util.HashSet)16 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Test (org.junit.Test)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 List (java.util.List)10 Map (java.util.Map)10 Status (com.sequenceiq.cloudbreak.api.model.Status)8 Collections.singletonMap (java.util.Collections.singletonMap)8 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)7 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 LinkedHashMap (java.util.LinkedHashMap)5 Set (java.util.Set)5