Search in sources :

Example 1 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class UserCreatorFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    CloudbreakUser cloudbreakUser = authenticatedUserService.getCbUser();
    if (cloudbreakUser != null) {
        userService.getOrCreate(cloudbreakUser);
    }
    filterChain.doFilter(request, response);
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Example 2 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class InstanceGroupV4RequestToHostGroupConverter method convert.

public HostGroup convert(InstanceGroupV4Request source) {
    HostGroup hostGroup = new HostGroup();
    hostGroup.setName(source.getName().toLowerCase());
    hostGroup.setRecoveryMode(source.getRecoveryMode());
    Set<String> recipeNames = source.getRecipeNames();
    if (!CollectionUtils.isEmpty(recipeNames)) {
        CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
        User user = userService.getOrCreate(cloudbreakUser);
        Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
        hostGroup.setRecipes(recipeService.getRecipesByNamesForWorkspace(workspace, recipeNames));
    }
    return hostGroup;
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 3 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class ImageCatalogToImageCatalogV4ResponseConverter method isDefault.

private boolean isDefault(String imageCatalogName) {
    CloudbreakUser cloudbreakUser = legacyRestRequestThreadLocalService.getCloudbreakUser();
    User user = userService.getOrCreate(cloudbreakUser);
    String defaultImageCatalogName = imageCatalogService.getDefaultImageCatalogName(user);
    return imageCatalogName.equals(defaultImageCatalogName) || (defaultImageCatalogName == null && imageCatalogService.isEnvDefault(imageCatalogName));
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Example 4 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class CloudbreakUserConfiguratorFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    CloudbreakUser cloudbreakUser = authenticatedUserService.getCbUser(request);
    if (cloudbreakUser != null) {
        userService.getOrCreate(cloudbreakUser);
    }
    legacyRestRequestThreadLocalService.setCloudbreakUser(cloudbreakUser);
    filterChain.doFilter(request, response);
    legacyRestRequestThreadLocalService.removeCloudbreakUser();
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Example 5 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser 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

CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)47 User (com.sequenceiq.cloudbreak.workspace.model.User)24 Test (org.junit.jupiter.api.Test)10 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)8 Optional (java.util.Optional)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)3 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Collection (java.util.Collection)3 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2