Search in sources :

Example 1 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class SdxServiceTest method testGetDefaultTemplate.

@Test
void testGetDefaultTemplate() {
    StackV4Request defaultTemplate = new StackV4Request();
    when(cdpConfigService.getConfigForKey(any())).thenReturn(defaultTemplate);
    SdxDefaultTemplateResponse response = underTest.getDefaultTemplate(LIGHT_DUTY, "7.2.14", "AWS");
    assertEquals(defaultTemplate, response.getTemplate());
}
Also used : SdxDefaultTemplateResponse(com.sequenceiq.sdx.api.model.SdxDefaultTemplateResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class StackToStackV4RequestConverter method prepareImage.

private void prepareImage(Stack source, StackV4Request stackV2Request) {
    try {
        Image image = componentConfigProviderService.getImage(source.getId());
        ImageSettingsV4Request is = new ImageSettingsV4Request();
        is.setId(Strings.isNullOrEmpty(image.getImageId()) ? "" : image.getImageId());
        is.setCatalog(Strings.isNullOrEmpty(image.getImageCatalogName()) ? "" : image.getImageCatalogName());
        stackV2Request.setImage(is);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info(e.toString());
    }
}
Also used : ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Example 3 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class StackToStackV4RequestConverter method convert.

public StackV4Request convert(Stack source) {
    StackV4Request stackV4Request = new StackV4Request();
    stackV4Request.setCloudPlatform(getIfNotNull(source.getCloudPlatform(), cp -> Enum.valueOf(CloudPlatform.class, cp)));
    stackV4Request.setEnvironmentCrn(source.getEnvironmentCrn());
    stackV4Request.setCustomDomain(getCustomDomainSettings(source));
    providerParameterCalculator.parse(new HashMap<>(source.getParameters()), stackV4Request);
    stackV4Request.setAuthentication(stackAuthenticationToStackAuthenticationV4RequestConverter.convert(source.getStackAuthentication()));
    stackV4Request.setNetwork(networkToNetworkV4RequestConverter.convert(source.getNetwork()));
    stackV4Request.setCluster(clusterToClusterV4RequestConverter.convert(source.getCluster()));
    stackV4Request.setExternalDatabase(getIfNotNull(source, stackToExternalDatabaseRequestConverter::convert));
    if (!source.getLoadBalancers().isEmpty()) {
        stackV4Request.setEnableLoadBalancer(true);
    }
    stackV4Request.setInstanceGroups(getInstanceGroups(source));
    prepareImage(source, stackV4Request);
    prepareTags(source, stackV4Request);
    prepareTelemetryRequest(source, stackV4Request);
    datalakeService.prepareDatalakeRequest(source, stackV4Request);
    stackV4Request.setPlacement(getPlacementSettings(source.getRegion(), source.getAvailabilityZone()));
    prepareInputs(source, stackV4Request);
    stackV4Request.setTimeToLive(getStackTimeToLive(source));
    return stackV4Request;
}
Also used : PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) TelemetryConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.TelemetryConverter) LoggerFactory(org.slf4j.LoggerFactory) DatalakeService(com.sequenceiq.cloudbreak.service.sharedservice.DatalakeService) HashMap(java.util.HashMap) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) Map(java.util.Map) CustomDomainSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.customdomain.CustomDomainSettingsV4Request) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) StackToExternalDatabaseRequestConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.StackToExternalDatabaseRequestConverter) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) Logger(org.slf4j.Logger) ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Set(java.util.Set) IOException(java.io.IOException) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) Collectors(java.util.stream.Collectors) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) List(java.util.List) Component(org.springframework.stereotype.Component) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) InstanceGroupNetworkToInstanceGroupNetworkV4RequestConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.instancegroup.network.InstanceGroupNetworkToInstanceGroupNetworkV4RequestConverter) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)

Example 4 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class StackV4RequestToTemplatePreparationObjectConverter method decorateBuilderWithPlacement.

private void decorateBuilderWithPlacement(StackV4Request source, Builder builder) {
    PlacementSettingsV4Request placementSettings = source.getPlacement();
    if (placementSettings != null) {
        String region = placementSettings.getRegion();
        builder.withPlacementView(new PlacementView(region, region));
    }
}
Also used : PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) PlacementView(com.sequenceiq.cloudbreak.template.views.PlacementView)

Example 5 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class StackDecorator method prepareInstanceGroups.

private void prepareInstanceGroups(Stack subject, StackV4Request request, Credential credential, User user, DetailedEnvironmentResponse environment) {
    Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponse = cloudParameterService.getInstanceGroupParameters(extendedCloudCredentialConverter.convert(credential), getInstanceGroupParameterRequests(subject));
    CloudbreakUser cloudbreakUser = legacyRestRequestThreadLocalService.getCloudbreakUser();
    subject.getInstanceGroups().parallelStream().forEach(instanceGroup -> {
        subject.getCluster().getHostGroups().stream().filter(hostGroup -> hostGroup.getName().equals(instanceGroup.getGroupName())).forEach(hostGroup -> hostGroup.setInstanceGroup(instanceGroup));
        legacyRestRequestThreadLocalService.setCloudbreakUser(cloudbreakUser);
        updateInstanceGroupParameters(instanceGroupParameterResponse, instanceGroup);
        if (instanceGroup.getTemplate() != null) {
            Template template = instanceGroup.getTemplate();
            if (template.getId() == null) {
                template.setCloudPlatform(credential.cloudPlatform());
                PlacementSettingsV4Request placement = request.getPlacement();
                String availabilityZone = placement != null ? placement.getAvailabilityZone() : subject.getAvailabilityZone();
                String region = placement != null ? placement.getRegion() : subject.getRegion();
                CdpResourceType cdpResourceType = cdpResourceTypeProvider.fromStackType(request.getType());
                template = templateDecorator.decorate(credential, template, region, availabilityZone, subject.getPlatformVariant(), cdpResourceType);
                template.setWorkspace(subject.getWorkspace());
                setupDatabaseAttachedVolume(subject, instanceGroup, template);
                template = templateService.create(user, template);
                instanceGroup.setTemplate(template);
            }
        }
        if (instanceGroup.getSecurityGroup() != null) {
            SecurityGroup securityGroup = instanceGroup.getSecurityGroup();
            if (securityGroup.getId() == null) {
                securityGroup.setCloudPlatform(credential.cloudPlatform());
                securityGroup.setWorkspace(subject.getWorkspace());
                securityGroup = securityGroupService.create(user, securityGroup);
                instanceGroup.setSecurityGroup(securityGroup);
            }
        }
        if (instanceGroup.getInstanceGroupNetwork() != null) {
            InstanceGroupNetwork ign = instanceGroup.getInstanceGroupNetwork();
            instanceGroup.setAvailabilityZones(getAvailabilityZoneFromEnv(instanceGroup, environment));
            if (ign.getId() == null) {
                ign.setCloudPlatform(credential.cloudPlatform());
                ign = instanceGroupNetworkService.create(ign);
                instanceGroup.setInstanceGroupNetwork(ign);
            }
        }
    });
}
Also used : InstanceGroupToInstanceGroupParameterRequestConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.instancegroup.InstanceGroupToInstanceGroupParameterRequestConverter) ResourceGroupUsage(com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage) LoggerFactory(org.slf4j.LoggerFactory) Measure(com.sequenceiq.cloudbreak.aspect.Measure) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) AzureEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) EmbeddedDatabaseService(com.sequenceiq.cloudbreak.service.cluster.EmbeddedDatabaseService) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialToExtendedCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToExtendedCloudCredentialConverter) NetworkService(com.sequenceiq.cloudbreak.service.network.NetworkService) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) VolumeUsageType(com.sequenceiq.cloudbreak.domain.VolumeUsageType) CredentialConverter(com.sequenceiq.cloudbreak.service.environment.credential.CredentialConverter) SharedServiceValidator(com.sequenceiq.cloudbreak.service.stack.SharedServiceValidator) PlatformOrchestrators(com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Set(java.util.Set) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) EmbeddedDatabaseConfig(com.sequenceiq.cloudbreak.conf.EmbeddedDatabaseConfig) TemplateService(com.sequenceiq.cloudbreak.service.template.TemplateService) Optional(java.util.Optional) LegacyRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.LegacyRestRequestThreadLocalService) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) SecurityGroupService(com.sequenceiq.cloudbreak.service.securitygroup.SecurityGroupService) Network(com.sequenceiq.cloudbreak.domain.Network) CdpResourceTypeProvider(com.sequenceiq.cloudbreak.service.CdpResourceTypeProvider) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Orchestrator(com.sequenceiq.cloudbreak.cloud.model.Orchestrator) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) InstanceGroupNetworkService(com.sequenceiq.cloudbreak.service.network.instancegroup.InstanceGroupNetworkService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Nonnull(javax.annotation.Nonnull) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) InstanceGroupParameterRequest(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterRequest) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) CloudParameterService(com.sequenceiq.cloudbreak.cloud.service.CloudParameterService) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) User(com.sequenceiq.cloudbreak.workspace.model.User) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) InstanceGroupParameterResponse(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse) CloudParameterCache(com.sequenceiq.cloudbreak.service.stack.CloudParameterCache) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) InstanceGroupParameterResponse(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) Template(com.sequenceiq.cloudbreak.domain.Template)

Aggregations

StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)105 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)66 Test (org.junit.jupiter.api.Test)58 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)52 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)36 Test (org.junit.Test)36 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)34 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)32 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)31 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)17 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)14 Map (java.util.Map)13 Set (java.util.Set)13 Optional (java.util.Optional)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)11 HashMap (java.util.HashMap)11 List (java.util.List)11