Search in sources :

Example 1 with CdpResourceType

use of com.sequenceiq.common.api.type.CdpResourceType 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)1 PlacementSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request)1 Measure (com.sequenceiq.cloudbreak.aspect.Measure)1 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)1 PlatformParametersConsts (com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 InstanceGroupParameterRequest (com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterRequest)1 InstanceGroupParameterResponse (com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse)1 Orchestrator (com.sequenceiq.cloudbreak.cloud.model.Orchestrator)1 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)1 PlatformOrchestrators (com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators)1 CloudParameterService (com.sequenceiq.cloudbreak.cloud.service.CloudParameterService)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 NetworkConstants (com.sequenceiq.cloudbreak.common.network.NetworkConstants)1 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)1 EmbeddedDatabaseConfig (com.sequenceiq.cloudbreak.conf.EmbeddedDatabaseConfig)1 CredentialToExtendedCloudCredentialConverter (com.sequenceiq.cloudbreak.converter.spi.CredentialToExtendedCloudCredentialConverter)1 InstanceGroupToInstanceGroupParameterRequestConverter (com.sequenceiq.cloudbreak.converter.v4.stacks.instancegroup.InstanceGroupToInstanceGroupParameterRequestConverter)1