use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request 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.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.
the class SdxServiceTest method testCreateSdxClusterWithCustomRequestContainsImageInfo.
@Test
void testCreateSdxClusterWithCustomRequestContainsImageInfo() throws Exception {
ImageV4Response imageResponse = getImageResponse();
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.7/aws/light_duty.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
SdxCustomClusterRequest sdxClusterRequest = createSdxCustomClusterRequest(LIGHT_DUTY, "cdp-default", "imageId_1");
setSpot(sdxClusterRequest);
withCloudStorage(sdxClusterRequest);
when(imageCatalogService.getImageResponseFromImageRequest(eq(sdxClusterRequest.getImageSettingsV4Request()), any())).thenReturn(imageResponse);
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));
SdxCluster createdSdxCluster = result.getLeft();
StackV4Request stackV4Request = JsonUtil.readValue(createdSdxCluster.getStackRequest(), StackV4Request.class);
assertNotNull(stackV4Request.getImage());
assertEquals("cdp-default", stackV4Request.getImage().getCatalog());
assertEquals("imageId_1", stackV4Request.getImage().getId());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.
the class StackRequestManifesterTest method setupInstanceVolumeEncryptionTestWhenAzureAndDiskEncryptionSetIdAndTwoInstanceGroups.
@Test
void setupInstanceVolumeEncryptionTestWhenAzureAndDiskEncryptionSetIdAndTwoInstanceGroups() {
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setAzure(AzureEnvironmentParameters.builder().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).withEncryptionKeyUrl(ENCRYPTION_KEY).build()).build());
envResponse.setCloudPlatform(CloudPlatform.AZURE.name());
InstanceGroupV4Request instanceGroupV4Request1 = createInstanceGroupV4Request();
InstanceTemplateV4Request instanceTemplateV4Request1 = instanceGroupV4Request1.getTemplate();
InstanceGroupV4Request instanceGroupV4Request2 = createInstanceGroupV4Request();
InstanceTemplateV4Request instanceTemplateV4Request2 = instanceGroupV4Request2.getTemplate();
instanceTemplateV4Request2.createAzure().setEncryption(createAzureEncryptionV4Parameters(EncryptionType.CUSTOM, ENCRYPTION_KEY));
when(stackV4Request.getInstanceGroups()).thenReturn(List.of(instanceGroupV4Request1, instanceGroupV4Request2));
underTest.setupInstanceVolumeEncryption(stackV4Request, envResponse);
verifyAzureEncryption(instanceTemplateV4Request1, EncryptionType.CUSTOM, DISK_ENCRYPTION_SET_ID, ENCRYPTION_KEY);
verifyAzureEncryption(instanceTemplateV4Request2, EncryptionType.CUSTOM, DISK_ENCRYPTION_SET_ID, ENCRYPTION_KEY);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.
the class StackRequestManifesterTest method setupInstanceVolumeEncryptionTestWhenAzureAndEncryptionAtHostAndNoInstanceGroups.
@Test
void setupInstanceVolumeEncryptionTestWhenAzureAndEncryptionAtHostAndNoInstanceGroups() {
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setAccountId(ACCOUNT_ID);
envResponse.setCloudPlatform(CloudPlatform.AZURE.name());
List<InstanceGroupV4Request> instanceGroups = new ArrayList<>();
when(stackV4Request.getInstanceGroups()).thenReturn(instanceGroups);
underTest.setupInstanceVolumeEncryption(stackV4Request, envResponse);
assertThat(instanceGroups).isEmpty();
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.
the class StackRequestManifesterTest method setupInstanceVolumeEncryptionTestWhenAzureAndDiskEncryptionSetIdAndNoInstanceGroups.
@Test
void setupInstanceVolumeEncryptionTestWhenAzureAndDiskEncryptionSetIdAndNoInstanceGroups() {
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setCloudPlatform(CloudPlatform.AZURE.name());
envResponse.setAzure(AzureEnvironmentParameters.builder().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).withEncryptionKeyUrl(ENCRYPTION_KEY).build()).build());
List<InstanceGroupV4Request> instanceGroups = new ArrayList<>();
when(stackV4Request.getInstanceGroups()).thenReturn(instanceGroups);
underTest.setupInstanceVolumeEncryption(stackV4Request, envResponse);
assertThat(instanceGroups).isEmpty();
}
Aggregations