Search in sources :

Example 1 with CloudbreakEventService

use of com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService 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)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Maps (com.google.common.collect.Maps)1 InstanceMetadataType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 SERVICES_UNHEALTHY (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)1 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)1 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1 GatewayConfigService (com.sequenceiq.cloudbreak.service.GatewayConfigService)1 InstanceMetadataUpdater (com.sequenceiq.cloudbreak.service.cluster.InstanceMetadataUpdater)1 Package (com.sequenceiq.cloudbreak.service.cluster.Package)1