use of com.sequenceiq.flow.api.model.FlowIdentifier 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.flow.api.model.FlowIdentifier 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}}");
}
use of com.sequenceiq.flow.api.model.FlowIdentifier 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.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class SdxCcmUpgradeServiceTest method testTriggerUpgrade.
@Test
void testTriggerUpgrade() {
SdxCluster sdxCluster = getSdxCluster();
when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(List.of(sdxCluster));
when(sdxService.getAccountIdFromCrn(any())).thenReturn(ACCOUNT_ID);
when(sdxService.getDetail(CLUSTER_NAME, null, ACCOUNT_ID)).thenReturn(getStack(Tunnel.CCM, Status.AVAILABLE));
when(messagesService.getMessage(any(), any())).thenReturn("success");
FlowIdentifier flowId = new FlowIdentifier(FlowType.FLOW, "flowId");
when(sdxReactorFlowManager.triggerCcmUpgradeFlow(sdxCluster)).thenReturn(flowId);
SdxCcmUpgradeResponse response = underTest.upgradeCcm(ENV_CRN);
assertThat(response.getReason()).isEqualTo("success");
assertThat(response.getFlowIdentifier()).isEqualTo(flowId);
}
use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class SdxUpgradeRecoveryServiceTest method testValidateStatusSuccessfulShouldStartRecoveryFlow.
@Test
public void testValidateStatusSuccessfulShouldStartRecoveryFlow() {
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
String reason = "Datalake upgrade recovery requested. Cluster will be terminated and re-launched with the original runtime.";
RecoveryValidationV4Response recoveryV4Response = new RecoveryValidationV4Response(reason, RecoveryStatus.RECOVERABLE);
when(stackV4Endpoint.getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN)).thenReturn(recoveryV4Response);
when(sdxReactorFlowManager.triggerDatalakeRuntimeRecoveryFlow(cluster, SdxRecoveryType.RECOVER_WITHOUT_DATA)).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster));
assertEquals(reason, sdxRecoverableResponse.getReason());
SdxRecoveryResponse response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerRecovery(cluster, request));
assertEquals(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"), response.getFlowIdentifier());
}
Aggregations