Search in sources :

Example 71 with StackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.

the class StackCreationHandlerTest method acceptTest.

@Test
void acceptTest() {
    long stackId = 2L;
    StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    StackV4Response stackV4Response = new StackV4Response();
    when(provisionerService.waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class))).thenReturn(stackV4Response);
    stackCreationHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(sdxService, times(1)).updateRuntimeVersionFromStackResponse(any(), eq(stackV4Response));
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("StackCreationSuccessEvent", eventNotified);
    Assertions.assertEquals(StackCreationSuccessEvent.class, event.getData().getClass());
    Assertions.assertEquals(stackId, ((StackCreationSuccessEvent) event.getData()).getResourceId());
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(STACK_CREATION_FINISHED, "Datalake stack created", (Long) stackId);
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) Event(reactor.bus.Event) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test)

Example 72 with StackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverterTest method testConvertWithoutCluster.

@Test
public void testConvertWithoutCluster() throws CloudbreakImageNotFoundException {
    Stack source = getSource();
    // GIVEN
    getSource().setCluster(null);
    given(imageService.getImage(source.getId())).willReturn(mock(Image.class));
    given(imageToStackImageV4ResponseConverter.convert(any())).willReturn(new StackImageV4Response());
    given(stackToCustomDomainsSettingsV4Response.convert(any())).willReturn(new CustomDomainSettingsV4Response());
    given(stackAuthenticationToStackAuthenticationV4ResponseConverter.convert(any())).willReturn(new StackAuthenticationV4Response());
    given(networkToNetworkV4ResponseConverter.convert(any())).willReturn(new NetworkV4Response());
    given(workspaceToWorkspaceResourceV4ResponseConverter.convert(any())).willReturn(new WorkspaceResourceV4Response());
    given(cloudbreakDetailsToCloudbreakDetailsV4ResponseConverter.convert(any())).willReturn(new CloudbreakDetailsV4Response());
    given(stackToPlacementSettingsV4ResponseConverter.convert(any())).willReturn(new PlacementSettingsV4Response());
    given(telemetryConverter.convert(any())).willReturn(new TelemetryResponse());
    given(instanceGroupToInstanceGroupV4ResponseConverter.convert(any())).willReturn(new InstanceGroupV4Response());
    given(databaseAvailabilityTypeToDatabaseResponseConverter.convert(any(), any())).willReturn(new DatabaseResponse());
    // WHEN
    StackV4Response result = underTest.convert(source);
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("cluster", "gcp", "mock", "openstack", "aws", "yarn", "azure", "telemetry", "environmentName", "credentialName", "credentialCrn", "telemetry", "flowIdentifier", "loadBalancers"));
    assertNull(result.getCluster());
    verify(restRequestThreadLocalService).setWorkspace(source.getWorkspace());
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) DatabaseResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseResponse) CustomDomainSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.customdomain.CustomDomainSettingsV4Response) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) WorkspaceResourceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.workspace.responses.WorkspaceResourceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackAuthenticationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.authentication.StackAuthenticationV4Response) NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) CloudbreakDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CloudbreakDetailsV4Response) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) PlacementSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.PlacementSettingsV4Response) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 73 with StackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverterTest method setUp.

@Before
public void setUp() throws CloudbreakImageNotFoundException {
    underTest = new StackToStackV4ResponseConverter();
    MockitoAnnotations.initMocks(this);
    when(imageService.getImage(anyLong())).thenReturn(new Image("cb-centos66-amb200-2015-05-25", Collections.emptyMap(), "redhat6", "redhat6", "", "default", "default-id", new HashMap<>()));
    when(componentConfigProviderService.getCloudbreakDetails(anyLong())).thenReturn(new CloudbreakDetails("version"));
    when(componentConfigProviderService.getStackTemplate(anyLong())).thenReturn(new StackTemplate("{}", "version"));
    when(componentConfigProviderService.getTelemetry(anyLong())).thenReturn(new Telemetry());
    Mockito.doAnswer(answer -> {
        StackV4Response result = answer.getArgument(1, StackV4Response.class);
        result.setSharedService(new SharedServiceV4Response());
        return null;
    }).when(datalakeService).addSharedServiceResponse(any(Stack.class), any(StackV4Response.class));
    when(serviceEndpointCollector.filterByStackType(any(StackType.class), any(List.class))).thenReturn(new ArrayList());
    credentialResponse = new CredentialResponse();
    credentialResponse.setName("cred-name");
    credentialResponse.setCrn("crn");
    when(loadBalancerService.findByStackId(any())).thenReturn(Set.of());
}
Also used : HashMap(java.util.HashMap) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) ArrayList(java.util.ArrayList) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) SharedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.sharedservice.SharedServiceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) StackToStackV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackToStackV4ResponseConverter) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) List(java.util.List) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 74 with StackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverterTest method testConvertWithLoadBalancers.

@Test
public void testConvertWithLoadBalancers() throws CloudbreakImageNotFoundException {
    Set<LoadBalancer> loadBalancers = Set.of(new LoadBalancer());
    Stack source = getSource();
    // GIVEN
    given(imageService.getImage(source.getId())).willReturn(mock(Image.class));
    given(imageToStackImageV4ResponseConverter.convert(any())).willReturn(new StackImageV4Response());
    given(stackToCustomDomainsSettingsV4Response.convert(any())).willReturn(new CustomDomainSettingsV4Response());
    given(stackAuthenticationToStackAuthenticationV4ResponseConverter.convert(any())).willReturn(new StackAuthenticationV4Response());
    given(networkToNetworkV4ResponseConverter.convert(any())).willReturn(new NetworkV4Response());
    given(workspaceToWorkspaceResourceV4ResponseConverter.convert(any())).willReturn(new WorkspaceResourceV4Response());
    given(cloudbreakDetailsToCloudbreakDetailsV4ResponseConverter.convert(any())).willReturn(new CloudbreakDetailsV4Response());
    given(stackToPlacementSettingsV4ResponseConverter.convert(any())).willReturn(new PlacementSettingsV4Response());
    given(telemetryConverter.convert(any())).willReturn(new TelemetryResponse());
    given(instanceGroupToInstanceGroupV4ResponseConverter.convert(any())).willReturn(new InstanceGroupV4Response());
    given(databaseAvailabilityTypeToDatabaseResponseConverter.convert(any(), any())).willReturn(new DatabaseResponse());
    given(loadBalancerService.findByStackId(any())).willReturn(loadBalancers);
    // WHEN
    source.setLoadBalancers(loadBalancers);
    StackV4Response result = underTest.convert(source);
    // THEN
    assertNotNull(result.getLoadBalancers());
    assertTrue(result.isEnableLoadBalancer());
    verify(restRequestThreadLocalService).setWorkspace(source.getWorkspace());
}
Also used : TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) DatabaseResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CustomDomainSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.customdomain.CustomDomainSettingsV4Response) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) WorkspaceResourceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.workspace.responses.WorkspaceResourceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackAuthenticationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.authentication.StackAuthenticationV4Response) NetworkV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.network.NetworkV4Response) CloudbreakDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CloudbreakDetailsV4Response) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) PlacementSettingsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.PlacementSettingsV4Response) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 75 with StackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.

the class StackOperationsTest method testGetWhenNameOrCrnNameFilledThenProperGetCalled.

@Test
public void testGetWhenNameOrCrnNameFilledThenProperGetCalled() {
    StackV4Response expected = stackResponse();
    NameOrCrn nameOrCrn = NameOrCrn.ofName(stack.getName());
    when(stackCommonService.findStackByNameOrCrnAndWorkspaceId(nameOrCrn, stack.getWorkspace().getId(), STACK_ENTRIES, STACK_TYPE)).thenReturn(expected);
    StackV4Response result = underTest.get(nameOrCrn, stack.getWorkspace().getId(), STACK_ENTRIES, STACK_TYPE);
    assertEquals(expected, result);
    verify(stackCommonService, times(1)).findStackByNameOrCrnAndWorkspaceId(nameOrCrn, stack.getWorkspace().getId(), STACK_ENTRIES, STACK_TYPE);
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.Test)

Aggregations

StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)101 Test (org.junit.jupiter.api.Test)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)22 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)19 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)13 Test (org.junit.Test)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)8 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)8 MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)7 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)7 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)7 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)7 InstanceGroupV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response)6 TagsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response)6 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)6 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)6 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)6