use of com.sequenceiq.sdx.api.model.SdxClusterResponse in project cloudbreak by hortonworks.
the class ClusterCreationEnvironmentValidatorTest method testValidateShouldBeSuccessWhenStackRegionIsRegionNameAndEnvironmentsRegionsAreRegionNames.
@Test
void testValidateShouldBeSuccessWhenStackRegionIsRegionNameAndEnvironmentsRegionsAreRegionNames() {
// GIVEN
String westUs2RegionName = "westus2";
String westUs2RegionDisplayName = "West US 2";
Stack stack = getStack();
stack.setRegion(westUs2RegionName);
DetailedEnvironmentResponse environment = getEnvironmentResponse();
CompactRegionResponse regions = new CompactRegionResponse();
regions.getNames().add(westUs2RegionName);
regions.getNames().add("westus");
environment.setRegions(regions);
when(connector.displayNameToRegion(any())).thenReturn(westUs2RegionName);
when(connector.regionToDisplayName(any())).thenReturn(westUs2RegionDisplayName);
when(sdxClientService.getByEnvironmentCrn(any())).thenReturn(Arrays.asList(new SdxClusterResponse()));
ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();
// WHEN
underTest.validate(stack, environment, true, validationBuilder);
// THEN
ValidationResult actualResult = validationBuilder.build();
assertFalse(actualResult.hasError());
}
use of com.sequenceiq.sdx.api.model.SdxClusterResponse in project cloudbreak by hortonworks.
the class ClusterCreationEnvironmentValidatorTest method testValidateShouldBeFailedWhenStackRegionIsInvalidAndEnvironmentsResourcesAreNotInGoodEnvironment.
@Test
void testValidateShouldBeFailedWhenStackRegionIsInvalidAndEnvironmentsResourcesAreNotInGoodEnvironment() {
// GIVEN
Stack stack = getStack();
stack.setRegion("region3");
when(connector.displayNameToRegion(any())).thenReturn("region666");
DetailedEnvironmentResponse environment = getEnvironmentResponse();
environment.getRegions().setNames(Lists.newArrayList("region1", "region2"));
environment.setName("env1");
when(sdxClientService.getByEnvironmentCrn(any())).thenReturn(Arrays.asList(new SdxClusterResponse()));
ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();
// WHEN
underTest.validate(stack, environment, true, validationBuilder);
// THEN
ValidationResult actualResult = validationBuilder.build();
assertTrue(actualResult.hasError());
assertEquals(1, actualResult.getErrors().size());
assertEquals("[region3] region is not enabled in [env1] environment. Enabled regions: [region1,region2]", actualResult.getErrors().get(0));
}
use of com.sequenceiq.sdx.api.model.SdxClusterResponse in project cloudbreak by hortonworks.
the class ClusterCreationEnvironmentValidatorTest method testValidateShouldBeSuccessWhenResourcesAreInTheSameEnvironmentOrGlobals.
@Test
void testValidateShouldBeSuccessWhenResourcesAreInTheSameEnvironmentOrGlobals() {
// GIVEN
Stack stack = getStack();
DetailedEnvironmentResponse environment = getEnvironmentResponse();
when(sdxClientService.getByEnvironmentCrn(any())).thenReturn(Arrays.asList(new SdxClusterResponse()));
ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();
// WHEN
underTest.validate(stack, environment, true, validationBuilder);
// THEN
ValidationResult actualResult = validationBuilder.build();
assertFalse(actualResult.hasError());
}
use of com.sequenceiq.sdx.api.model.SdxClusterResponse in project cloudbreak by hortonworks.
the class SdxControllerTest method getTest.
@Test
void getTest() {
SdxCluster sdxCluster = getValidSdxCluster();
when(sdxService.getByNameInAccount(anyString(), anyString())).thenReturn(sdxCluster);
SdxStatusEntity sdxStatusEntity = new SdxStatusEntity();
sdxStatusEntity.setStatus(DatalakeStatusEnum.REQUESTED);
sdxStatusEntity.setStatusReason("statusreason");
sdxStatusEntity.setCreated(1L);
when(sdxStatusService.getActualStatusForSdx(sdxCluster)).thenReturn(sdxStatusEntity);
ReflectionTestUtils.setField(sdxClusterConverter, "sdxStatusService", sdxStatusService);
SdxClusterResponse sdxClusterResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> sdxController.get(SDX_CLUSTER_NAME));
assertEquals(SDX_CLUSTER_NAME, sdxClusterResponse.getName());
assertEquals("test-env", sdxClusterResponse.getEnvironmentName());
assertEquals("crn:sdxcluster", sdxClusterResponse.getCrn());
assertEquals(SdxClusterStatusResponse.REQUESTED, sdxClusterResponse.getStatus());
assertEquals("statusreason", sdxClusterResponse.getStatusReason());
}
use of com.sequenceiq.sdx.api.model.SdxClusterResponse in project cloudbreak by hortonworks.
the class SdxController method create.
@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_DATALAKE)
public SdxClusterResponse create(@ValidStackNameFormat @ValidStackNameLength String name, @Valid SdxClusterRequest createSdxClusterRequest) {
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
Pair<SdxCluster, FlowIdentifier> result = sdxService.createSdx(userCrn, name, createSdxClusterRequest, null);
SdxCluster sdxCluster = result.getLeft();
metricService.incrementMetricCounter(MetricType.EXTERNAL_SDX_REQUESTED, sdxCluster);
SdxClusterResponse sdxClusterResponse = sdxClusterConverter.sdxClusterToResponse(sdxCluster);
sdxClusterResponse.setName(sdxCluster.getClusterName());
sdxClusterResponse.setFlowIdentifier(result.getRight());
return sdxClusterResponse;
}
Aggregations