use of com.sequenceiq.sdx.api.model.SdxClusterShape.MICRO_DUTY in project cloudbreak by hortonworks.
the class SdxServiceTest method testCreateSdxClusterWithCustomInstanceGroup.
@Test
void testCreateSdxClusterWithCustomInstanceGroup() throws Exception {
final String runtime = "7.2.12";
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
String microDutyJson = FileReaderUtils.readFileFromClasspath("/duties/" + runtime + "/aws/micro_duty.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(microDutyJson, StackV4Request.class));
when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, MICRO_DUTY);
when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
withCloudStorage(sdxClusterRequest);
withRecipe(sdxClusterRequest);
withCustomInstanceGroups(sdxClusterRequest);
RecipeViewV4Responses recipeViewV4Responses = new RecipeViewV4Responses();
RecipeViewV4Response recipeViewV4Response = new RecipeViewV4Response();
recipeViewV4Response.setName("post-install");
recipeViewV4Responses.setResponses(List.of(recipeViewV4Response));
when(recipeV4Endpoint.listInternal(anyLong(), anyString())).thenReturn(recipeViewV4Responses);
long id = 10L;
when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
sdxWithId.setId(id);
return sdxWithId;
});
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(clock.getCurrentTimeMillis()).thenReturn(1L);
mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
when(entitlementService.microDutySdxEnabled(anyString())).thenReturn(true);
when(entitlementService.isDatalakeSelectInstanceTypeEnabled(anyString())).thenReturn(true);
Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
SdxCluster createdSdxCluster = result.getLeft();
assertEquals(id, createdSdxCluster.getId());
ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
verify(sdxClusterRepository, times(1)).save(captor.capture());
verify(recipeV4Endpoint, times(1)).listInternal(anyLong(), anyString());
SdxCluster capturedSdx = captor.getValue();
assertEquals(MICRO_DUTY, capturedSdx.getClusterShape());
StackV4Request stackRequest = JsonUtil.readValue(capturedSdx.getStackRequest(), StackV4Request.class);
Optional<InstanceGroupV4Request> masterGroup = stackRequest.getInstanceGroups().stream().filter(instanceGroup -> "master".equals(instanceGroup.getName())).findAny();
assertTrue(masterGroup.isPresent());
assertEquals("verylarge", masterGroup.get().getTemplate().getInstanceType());
Optional<InstanceGroupV4Request> idbrokerGroup = stackRequest.getInstanceGroups().stream().filter(instanceGroup -> "idbroker".equals(instanceGroup.getName())).findAny();
assertTrue(idbrokerGroup.isPresent());
assertEquals("notverylarge", idbrokerGroup.get().getTemplate().getInstanceType());
}
Aggregations