Search in sources :

Example 1 with SERVICES_UNHEALTHY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.

the class InstanceMetadataUpdaterTest method updatePackageVersionsOnAllInstancesInstancePkgQueryFailed.

@Test
public void updatePackageVersionsOnAllInstancesInstancePkgQueryFailed() throws Exception {
    Stack stack = createStack();
    Map<String, Map<String, String>> hostPackageMap = Maps.newHashMap();
    hostPackageMap.put("instanceId", packageMap());
    hostPackageMap.put("hostByCmd", falsePackageMap());
    when(hostOrchestrator.getPackageVersionsFromAllHosts(any(GatewayConfig.class), any())).thenReturn(hostPackageMap);
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    underTest.updatePackageVersionsOnAllInstances(1L);
    verify(cloudbreakEventService, times(1)).fireCloudbreakEvent(anyLong(), anyString(), eq(ResourceEvent.CLUSTER_PACKAGE_VERSION_CANNOT_BE_QUERIED), anyCollection());
    verify(cloudbreakEventService, times(2)).fireCloudbreakEvent(anyLong(), anyString(), any(ResourceEvent.class), anyCollection());
    assertEquals(SERVICES_UNHEALTHY, stack.getInstanceGroups().stream().filter(instanceGroup -> instanceGroup.getInstanceMetaDataSet().stream().filter(instanceMetaData -> StringUtils.equals(instanceMetaData.getDiscoveryFQDN(), "hostByCmd")).findFirst().isPresent()).findFirst().get().getInstanceMetaDataSet().iterator().next().getInstanceStatus());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StringUtils(org.apache.commons.lang3.StringUtils) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) HashSet(java.util.HashSet) MockitoAnnotations(org.mockito.MockitoAnnotations) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) Package(com.sequenceiq.cloudbreak.service.cluster.Package) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Mockito.when(org.mockito.Mockito.when) Maps(com.google.common.collect.Maps) Mockito.verify(org.mockito.Mockito.verify) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Lists(org.assertj.core.util.Lists) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) InstanceMetadataUpdater(com.sequenceiq.cloudbreak.service.cluster.InstanceMetadataUpdater) PackageName(com.sequenceiq.cloudbreak.service.cluster.PackageName) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Collections(java.util.Collections) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.Test)

Example 2 with SERVICES_UNHEALTHY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.

the class ClusterOperationService method updateFailedNodes.

private void updateFailedNodes(Cluster cluster, Map<InstanceMetaData, Optional<String>> failedHostMetadata) throws TransactionExecutionException {
    if (!failedHostMetadata.isEmpty()) {
        Map<String, Optional<String>> hostNamesWithReason = failedHostMetadata.entrySet().stream().filter(e -> e.getKey().getDiscoveryFQDN() != null).collect(Collectors.toMap(e -> e.getKey().getDiscoveryFQDN(), e -> e.getValue()));
        Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY, SERVICES_RUNNING);
        InstanceStatus newState = SERVICES_UNHEALTHY;
        ResourceEvent clusterEvent = CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT;
        ResourceEvent hostEvent = CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT;
        updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
    }
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) Math.abs(java.lang.Math.abs) Measure(com.sequenceiq.cloudbreak.aspect.Measure) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) StatusRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) EnumSet(java.util.EnumSet) RecoveryMode(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode) CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) CLUSTER_STOP_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_STOP_IGNORED) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Sets(com.google.common.collect.Sets) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT) START_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StackStopRestrictionService(com.sequenceiq.cloudbreak.service.stack.StackStopRestrictionService) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ResourceType(com.sequenceiq.common.api.type.ResourceType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DECOMMISSION_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) BlueprintValidator(com.sequenceiq.cloudbreak.template.validation.BlueprintValidator) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) IOException(java.io.IOException) CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotAllowedStatusUpdate(com.sequenceiq.cloudbreak.util.NotAllowedStatusUpdate) User(com.sequenceiq.cloudbreak.workspace.model.User) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_START_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_START_IGNORED) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) UsageLoggingUtil(com.sequenceiq.cloudbreak.util.UsageLoggingUtil) BlueprintValidatorFactory(com.sequenceiq.cloudbreak.service.blueprint.BlueprintValidatorFactory) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Optional(java.util.Optional) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent)

Example 3 with SERVICES_UNHEALTHY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.

the class ClusterOperationService method updateNewHealthyNodes.

private void updateNewHealthyNodes(Cluster cluster, Set<String> newHealthyNodes) throws TransactionExecutionException {
    if (!newHealthyNodes.isEmpty()) {
        Map<String, Optional<String>> hostNamesWithReason = newHealthyNodes.stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
        Set<InstanceStatus> expectedStates = EnumSet.of(SERVICES_UNHEALTHY, SERVICES_RUNNING, DECOMMISSION_FAILED, FAILED);
        InstanceStatus newState = SERVICES_HEALTHY;
        ResourceEvent clusterEvent = CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT;
        updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.empty());
    }
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) Math.abs(java.lang.Math.abs) Measure(com.sequenceiq.cloudbreak.aspect.Measure) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) StatusRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) EnumSet(java.util.EnumSet) RecoveryMode(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode) CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) CLUSTER_STOP_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_STOP_IGNORED) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Sets(com.google.common.collect.Sets) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT) START_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StackStopRestrictionService(com.sequenceiq.cloudbreak.service.stack.StackStopRestrictionService) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ResourceType(com.sequenceiq.common.api.type.ResourceType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DECOMMISSION_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) BlueprintValidator(com.sequenceiq.cloudbreak.template.validation.BlueprintValidator) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) IOException(java.io.IOException) CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotAllowedStatusUpdate(com.sequenceiq.cloudbreak.util.NotAllowedStatusUpdate) User(com.sequenceiq.cloudbreak.workspace.model.User) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_START_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_START_IGNORED) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) UsageLoggingUtil(com.sequenceiq.cloudbreak.util.UsageLoggingUtil) BlueprintValidatorFactory(com.sequenceiq.cloudbreak.service.blueprint.BlueprintValidatorFactory) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Optional(java.util.Optional) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent)

Example 4 with SERVICES_UNHEALTHY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.

the class MockStackResponseGenerator method getMockStackV4Response.

public static StackV4Response getMockStackV4Response(String clusterCrn, String hostGroup, String fqdnBase, int currentHostGroupCount, boolean withUnhealthyInstances) {
    List<InstanceGroupV4Response> instanceGroupV4Responses = new ArrayList<>();
    InstanceMetaDataV4Response master1 = new InstanceMetaDataV4Response();
    master1.setDiscoveryFQDN("master1");
    master1.setInstanceId("test_instanceid" + "master1");
    instanceGroupV4Responses.add(instanceGroup("master", awsTemplate(), Set.of(master1)));
    InstanceMetaDataV4Response worker1 = new InstanceMetaDataV4Response();
    worker1.setDiscoveryFQDN("worker1");
    worker1.setInstanceId("test_instanceid" + "worker1");
    InstanceMetaDataV4Response worker2 = new InstanceMetaDataV4Response();
    worker2.setDiscoveryFQDN("worker2");
    worker2.setInstanceId("test_instanceid" + "worker2");
    instanceGroupV4Responses.add(instanceGroup("worker", awsTemplate(), Set.of(worker1, worker2)));
    Set fqdnToInstanceIds = new HashSet();
    if (!withUnhealthyInstances) {
        for (int i = 1; i <= currentHostGroupCount; i++) {
            InstanceMetaDataV4Response metadata1 = new InstanceMetaDataV4Response();
            metadata1.setDiscoveryFQDN(fqdnBase + i);
            metadata1.setInstanceId("test_instanceid_" + hostGroup + i);
            metadata1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
            fqdnToInstanceIds.add(metadata1);
        }
    } else {
        // Add nodes with InstanceStatuses STOPPED and SERVICES_UNHEALTHY
        List<InstanceStatus> unhealthyStatuses = List.of(InstanceStatus.STOPPED, InstanceStatus.SERVICES_UNHEALTHY);
        for (InstanceStatus status : unhealthyStatuses) {
            InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
            metadataResponse.setDiscoveryFQDN(fqdnBase + unhealthyStatuses.indexOf(status));
            metadataResponse.setInstanceId("test_instanceid_" + hostGroup + unhealthyStatuses.indexOf(status));
            metadataResponse.setInstanceStatus(status);
            fqdnToInstanceIds.add(metadataResponse);
        }
        // Add remaining healthy instances
        for (int i = unhealthyStatuses.size(); i < currentHostGroupCount; ++i) {
            InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
            metadataResponse.setDiscoveryFQDN(fqdnBase + i);
            metadataResponse.setInstanceId("test_instanceid_" + hostGroup + i);
            metadataResponse.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
            fqdnToInstanceIds.add(metadataResponse);
        }
    }
    instanceGroupV4Responses.add(instanceGroup(hostGroup, awsTemplate(), fqdnToInstanceIds));
    StackV4Response mockReponse = new StackV4Response();
    mockReponse.setCrn(clusterCrn);
    mockReponse.setInstanceGroups(instanceGroupV4Responses);
    mockReponse.setCloudPlatform(CloudPlatform.AWS);
    return mockReponse;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) HashSet(java.util.HashSet) Set(java.util.Set) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ArrayList(java.util.ArrayList) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) HashSet(java.util.HashSet)

Aggregations

InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 SERVICES_UNHEALTHY (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)3 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)3 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)3 CloudbreakEventService (com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService)3 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Map (java.util.Map)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Sets (com.google.common.collect.Sets)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)2 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)2 AVAILABLE (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE)2