use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.
the class SdxServiceTest method testCreateNOTInternalSdxClusterFromLightDutyTemplateWhenBaseLocationSpecifiedShouldCreateStackRequestWithSettedUpBaseLocation.
@Test
void testCreateNOTInternalSdxClusterFromLightDutyTemplateWhenBaseLocationSpecifiedShouldCreateStackRequestWithSettedUpBaseLocation() throws IOException, TransactionExecutionException {
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
// doNothing().when(cloudStorageLocationValidator.validate("s3a://some/dir", ));
SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, LIGHT_DUTY);
withCloudStorage(sdxClusterRequest);
long id = 10L;
when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
sdxWithId.setId(id);
return sdxWithId;
});
mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
SdxCluster createdSdxCluster = result.getLeft();
assertEquals("s3a://some/dir", createdSdxCluster.getCloudStorageBaseLocation());
}
use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.
the class SdxServiceTest method testSdxCreateMediumDutySdx.
@Test
void testSdxCreateMediumDutySdx() throws IOException, TransactionExecutionException {
final String runtime = "7.2.7";
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/" + runtime + "/aws/medium_duty_ha.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, MEDIUM_DUTY_HA);
when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
withCloudStorage(sdxClusterRequest);
long id = 10L;
when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
sdxWithId.setId(id);
return sdxWithId;
});
when(clock.getCurrentTimeMillis()).thenReturn(1L);
mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
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());
SdxCluster capturedSdx = captor.getValue();
assertEquals(MEDIUM_DUTY_HA, capturedSdx.getClusterShape());
}
use of com.sequenceiq.sdx.api.model.SdxClusterRequest 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());
}
use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.
the class SdxServiceTest method testCreateMicroDuty.
@Test
void testCreateMicroDuty() throws IOException, TransactionExecutionException {
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);
RecipeViewV4Responses recipeViewV4Responses = new RecipeViewV4Responses();
RecipeViewV4Response recipeViewV4Response = new RecipeViewV4Response();
recipeViewV4Response.setName("post-install");
recipeViewV4Responses.setResponses(List.of(recipeViewV4Response));
when(recipeV4Endpoint.listInternal(anyLong(), anyString())).thenReturn(recipeViewV4Responses);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
long id = 10L;
when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
sdxWithId.setId(id);
return sdxWithId;
});
when(clock.getCurrentTimeMillis()).thenReturn(1L);
mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
when(entitlementService.microDutySdxEnabled(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());
}
use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.
the class SdxServiceTest method testCreateSdxClusterWithSpotStackRequestContainsRequiredAttributes.
@Test
void testCreateSdxClusterWithSpotStackRequestContainsRequiredAttributes() throws IOException, TransactionExecutionException {
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, LIGHT_DUTY);
setSpot(sdxClusterRequest);
withCloudStorage(sdxClusterRequest);
long id = 10L;
when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
sdxWithId.setId(id);
return sdxWithId;
});
mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
SdxCluster createdSdxCluster = result.getLeft();
// AWS 7.1.0 light duty contains exactly 2 instance groups
assertThat(createdSdxCluster.getStackRequest()).containsSubsequence("{\"aws\":{\"spot\":{\"percentage\":100,\"maxPrice\":0.9}}", "{\"aws\":{\"spot\":{\"percentage\":100,\"maxPrice\":0.9}}");
}
Aggregations