Search in sources :

Example 21 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class SdxService method resizeSdx.

public Pair<SdxCluster, FlowIdentifier> resizeSdx(final String userCrn, final String clusterName, final SdxClusterResizeRequest sdxClusterResizeRequest) {
    LOGGER.info("Re-sizing SDX cluster with name {}", clusterName);
    String accountIdFromCrn = getAccountIdFromCrn(userCrn);
    String environmentName = sdxClusterResizeRequest.getEnvironment();
    SdxClusterShape shape = sdxClusterResizeRequest.getClusterShape();
    final SdxCluster sdxCluster = sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(accountIdFromCrn, clusterName).orElseThrow(() -> notFound("SDX cluster", clusterName).get());
    MDCBuilder.buildMdcContext(sdxCluster);
    validateSdxResizeRequest(sdxCluster, accountIdFromCrn, shape);
    StackV4Response stackV4Response = getDetail(clusterName, Set.of(StackResponseEntries.HARDWARE_INFO.getEntryName(), StackResponseEntries.EVENTS.getEntryName()), accountIdFromCrn);
    DetailedEnvironmentResponse environment = validateAndGetEnvironment(environmentName);
    SdxCluster newSdxCluster = validateAndCreateNewSdxCluster(userCrn, clusterName, sdxCluster.getRuntime(), shape, sdxCluster.isRangerRazEnabled(), sdxCluster.isEnableMultiAz(), environment);
    newSdxCluster.setTags(sdxCluster.getTags());
    newSdxCluster.setCrn(sdxCluster.getCrn());
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    if (!StringUtils.isBlank(sdxCluster.getCloudStorageBaseLocation())) {
        newSdxCluster.setCloudStorageBaseLocation(sdxCluster.getCloudStorageBaseLocation());
        newSdxCluster.setCloudStorageFileSystemType(sdxCluster.getCloudStorageFileSystemType());
    } else if (!CloudPlatform.YARN.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.GCP.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform.name())) {
        throw new BadRequestException("Cloud storage parameter is required.");
    }
    newSdxCluster.setDatabaseAvailabilityType(sdxCluster.getDatabaseAvailabilityType());
    newSdxCluster.setDatabaseEngineVersion(sdxCluster.getDatabaseEngineVersion());
    StackV4Request stackRequest = getStackRequest(shape, sdxCluster.isRangerRazEnabled(), null, cloudPlatform, sdxCluster.getRuntime(), null);
    if (shape == SdxClusterShape.MEDIUM_DUTY_HA) {
        // This is added to make sure the host name used by Light and Medium duty are not the same.
        CustomDomainSettingsV4Request customDomainSettingsV4Request = new CustomDomainSettingsV4Request();
        customDomainSettingsV4Request.setHostname(sdxCluster.getClusterName() + SDX_RESIZE_NAME_SUFFIX);
        stackRequest.setCustomDomain(customDomainSettingsV4Request);
    }
    prepareCloudStorageForStack(stackRequest, stackV4Response, newSdxCluster, environment);
    prepareDefaultSecurityConfigs(null, stackRequest, cloudPlatform);
    try {
        if (!StringUtils.isBlank(sdxCluster.getStackRequestToCloudbreak())) {
            StackV4Request stackV4RequestOrig = JsonUtil.readValue(sdxCluster.getStackRequestToCloudbreak(), StackV4Request.class);
            stackRequest.setImage(stackV4RequestOrig.getImage());
        }
    } catch (IOException ioException) {
        LOGGER.error("Failed to re-use the image catalog. Will use default catalog", ioException);
    }
    stackRequest.setResourceCrn(newSdxCluster.getCrn());
    newSdxCluster.setStackRequest(stackRequest);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxResize(sdxCluster.getId(), newSdxCluster);
    return Pair.of(sdxCluster, flowIdentifier);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) CustomDomainSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.customdomain.CustomDomainSettingsV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape)

Example 22 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverterTest method setUp.

@Before
public void setUp() throws CloudbreakImageNotFoundException {
    underTest = new StackToStackV4ResponseConverter();
    MockitoAnnotations.initMocks(this);
    when(imageService.getImage(anyLong())).thenReturn(new Image("cb-centos66-amb200-2015-05-25", Collections.emptyMap(), "redhat6", "redhat6", "", "default", "default-id", new HashMap<>()));
    when(componentConfigProviderService.getCloudbreakDetails(anyLong())).thenReturn(new CloudbreakDetails("version"));
    when(componentConfigProviderService.getStackTemplate(anyLong())).thenReturn(new StackTemplate("{}", "version"));
    when(componentConfigProviderService.getTelemetry(anyLong())).thenReturn(new Telemetry());
    Mockito.doAnswer(answer -> {
        StackV4Response result = answer.getArgument(1, StackV4Response.class);
        result.setSharedService(new SharedServiceV4Response());
        return null;
    }).when(datalakeService).addSharedServiceResponse(any(Stack.class), any(StackV4Response.class));
    when(serviceEndpointCollector.filterByStackType(any(StackType.class), any(List.class))).thenReturn(new ArrayList());
    credentialResponse = new CredentialResponse();
    credentialResponse.setName("cred-name");
    credentialResponse.setCrn("crn");
    when(loadBalancerService.findByStackId(any())).thenReturn(Set.of());
}
Also used : HashMap(java.util.HashMap) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) ArrayList(java.util.ArrayList) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) SharedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.sharedservice.SharedServiceV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) StackToStackV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackToStackV4ResponseConverter) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) List(java.util.List) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 23 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class StackV4RequestToStackConverterTest method testWhenProvidedRegionIsEmptyButDefaultOnesAreNotAndPlatformRegionIsNullThenBadRequestExceptionComes.

@Test
void testWhenProvidedRegionIsEmptyButDefaultOnesAreNotAndPlatformRegionIsNullThenBadRequestExceptionComes() {
    setDefaultRegions(AWS);
    StackV4Request request = getRequest("stack.json");
    request.setCloudPlatform(MOCK);
    request.getPlacement().setRegion(null);
    BadRequestException resultException = assertThrows(BadRequestException.class, () -> underTest.convert(request));
    assertEquals(String.format("No default region specified for: %s. Region cannot be empty.", request.getCloudPlatform().name()), resultException.getMessage());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest) Test(org.junit.jupiter.api.Test)

Example 24 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class ImageToStackImageV4ResponseConverter method convert.

public StackImageV4Response convert(Image source) {
    StackImageV4Response image = new StackImageV4Response();
    image.setName(source.getImageName());
    decorateWithImageCatalogUrl(source, image);
    image.setCatalogName(Strings.isNullOrEmpty(source.getImageCatalogName()) ? "cloudbreak-default" : source.getImageCatalogName());
    image.setId(Strings.isNullOrEmpty(source.getImageId()) ? null : source.getImageId());
    return image;
}
Also used : StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response)

Example 25 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class NetworkV1ToNetworkV4Converter method convertToNetworkV4Request.

public NetworkV4Request convertToNetworkV4Request(Pair<NetworkV1Request, DetailedEnvironmentResponse> network) {
    EnvironmentNetworkResponse value = network.getValue().getNetwork();
    NetworkV1Request key = network.getKey();
    if (key == null) {
        key = new NetworkV1Request();
    }
    NetworkV4Request request = new NetworkV4Request();
    if (network.getValue().getCloudPlatform() == null) {
        throw new IllegalStateException("Unable to determine cloud platform for network since it has not been set!");
    }
    switch(network.getValue().getCloudPlatform()) {
        case "AWS":
            request.setAws(getAwsNetworkParameters(Optional.ofNullable(key.getAws()), value));
            break;
        case "AZURE":
            request.setAzure(getAzureNetworkParameters(Optional.ofNullable(key.getAzure()), value));
            break;
        case "MOCK":
            request.setMock(getMockNetworkParameters(Optional.ofNullable(key.getMock()), value));
            break;
        case "GCP":
            request.setGcp(getGcpNetworkParameters(Optional.ofNullable(key.getGcp()), value));
            break;
        default:
            LOGGER.warn(NetworkV1ToNetworkV4Converter.class.getSimpleName() + " has no implemented action for cloud platform: " + network.getValue().getCloudPlatform());
    }
    return request;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)13 List (java.util.List)10 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Inject (javax.inject.Inject)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Service (org.springframework.stereotype.Service)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 Map (java.util.Map)5 Optional (java.util.Optional)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 HashSet (java.util.HashSet)4 Sets (com.google.common.collect.Sets)3 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 BlueprintService (com.sequenceiq.cloudbreak.service.blueprint.BlueprintService)3 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)3