use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class SdxServiceTest method testDeleteSdxWhenNameIsProvidedShouldInitiateSdxDeletionFlow.
@Test
void testDeleteSdxWhenNameIsProvidedShouldInitiateSdxDeletionFlow() {
SdxCluster sdxCluster = getSdxCluster();
when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNull(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
when(sdxReactorFlowManager.triggerSdxDeletion(any(SdxCluster.class), anyBoolean())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
mockCBCallForDistroXClusters(Sets.newHashSet());
underTest.deleteSdx(USER_CRN, "sdx-cluster-name", true);
verify(sdxReactorFlowManager, times(1)).triggerSdxDeletion(sdxCluster, true);
ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
verify(sdxClusterRepository, times(1)).save(captor.capture());
verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_REQUESTED, "Datalake deletion requested", sdxCluster);
}
use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class SdxServiceTest method testSdxResizeClusterSuccess.
@Test
void testSdxResizeClusterSuccess() throws Exception {
final String runtime = "7.2.10";
SdxClusterResizeRequest sdxClusterResizeRequest = new SdxClusterResizeRequest();
sdxClusterResizeRequest.setClusterShape(MEDIUM_DUTY_HA);
sdxClusterResizeRequest.setEnvironment("environment");
SdxCluster sdxCluster = getSdxCluster();
sdxCluster.setId(1L);
sdxCluster.setClusterShape(LIGHT_DUTY);
sdxCluster.setDatabaseCrn(null);
sdxCluster.setRuntime(runtime);
sdxCluster.setCloudStorageBaseLocation("s3a://some/dir/");
when(entitlementService.isDatalakeLightToMediumMigrationEnabled(anyString())).thenReturn(true);
when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
when(sdxClusterRepository.findByAccountIdAndEnvCrnAndDeletedIsNullAndDetachedIsTrue(anyString(), anyString())).thenReturn(Optional.empty());
mockEnvironmentCall(sdxClusterResizeRequest, CloudPlatform.AWS);
when(sdxReactorFlowManager.triggerSdxResize(anyLong(), any(SdxCluster.class))).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
String mediumDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.10/aws/medium_duty_ha.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(mediumDutyJson, StackV4Request.class));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
StackV4Response stackV4Response = new StackV4Response();
stackV4Response.setStatus(Status.STOPPED);
when(stackV4Endpoint.get(anyLong(), anyString(), anySet(), anyString())).thenReturn(stackV4Response);
Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.resizeSdx(USER_CRN, sdxCluster.getClusterName(), sdxClusterResizeRequest));
SdxCluster createdSdxCluster = result.getLeft();
assertEquals(sdxCluster.getClusterName(), createdSdxCluster.getClusterName());
assertEquals(runtime, createdSdxCluster.getRuntime());
assertEquals("s3a://some/dir/", createdSdxCluster.getCloudStorageBaseLocation());
assertEquals("envir", createdSdxCluster.getEnvName());
}
use of com.sequenceiq.flow.api.model.FlowIdentifier 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.flow.api.model.FlowIdentifier 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.flow.api.model.FlowIdentifier 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