Search in sources :

Example 46 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class WorkspaceConfiguratorFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    CloudbreakUser cloudbreakUser = authenticatedUserService.getCbUser(request);
    try {
        if (cloudbreakUser != null) {
            if (ThreadBasedUserCrnProvider.getUserCrn() != null && !ThreadBasedUserCrnProvider.getUserCrn().equals(cloudbreakUser.getUserCrn())) {
                LOGGER.debug("Before:There is a difference between:: Spring security context: {} and header-based-actor: '{}'", cloudbreakUser.getUserCrn(), ThreadBasedUserCrnProvider.getUserCrn());
                logHeadersSafely(request);
            }
            User user = userService.getOrCreate(cloudbreakUser);
            String accountId = Crn.fromString(cloudbreakUser.getUserCrn()).getAccountId();
            // default workspaceName is always the accountId
            Optional<Workspace> tenantDefaultWorkspace = workspaceService.getByName(accountId, user);
            if (!tenantDefaultWorkspace.isPresent()) {
                throw new IllegalStateException("Tenant default workspace does not exist!");
            }
            if (ThreadBasedUserCrnProvider.getUserCrn() != null && !ThreadBasedUserCrnProvider.getUserCrn().equals(user.getUserCrn())) {
                LOGGER.debug("Before:There is a difference between:: CB user context: {} and header-based-actor: '{}'", user.getUserCrn(), ThreadBasedUserCrnProvider.getUserCrn());
            }
            Long workspaceId = tenantDefaultWorkspace.get().getId();
            restRequestThreadLocalService.setRequestedWorkspaceId(workspaceId);
            WorkspaceIdModifiedRequest modifiedRequest = new WorkspaceIdModifiedRequest(request, workspaceId);
            LOGGER.debug("Before:CloudbreakRestRequestThreadLocalContext: {}", restRequestThreadLocalService.getRestThreadLocalContextAsString());
            filterChain.doFilter(modifiedRequest, response);
            LOGGER.debug("After:CloudbreakRestRequestThreadLocalContext: {}", restRequestThreadLocalService.getRestThreadLocalContextAsString());
        } else {
            filterChain.doFilter(request, response);
        }
    } finally {
        restRequestThreadLocalService.removeRequestedWorkspaceId();
    }
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 47 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class BlueprintLoaderService method getResultSetFromUpdateAndOriginalBlueprints.

private Iterable<Blueprint> getResultSetFromUpdateAndOriginalBlueprints(Collection<Blueprint> blueprints, Iterable<Blueprint> blueprintsWhichAreMissing, Workspace workspace, BiFunction<Iterable<Blueprint>, Workspace, Iterable<Blueprint>> saveMethod) {
    LOGGER.debug("Updating blueprints which should be modified.");
    Iterable<Blueprint> savedBlueprints = saveMethod.apply(blueprintsWhichAreMissing, workspace);
    LOGGER.debug("Finished to update blueprints which should be modified.");
    Map<String, Blueprint> resultBlueprints = new HashMap<>();
    for (Blueprint blueprint : blueprints.stream().filter(bp -> DEFAULT.equals(bp.getStatus())).collect(Collectors.toSet())) {
        resultBlueprints.put(blueprint.getName(), blueprint);
    }
    for (Blueprint savedBlueprint : savedBlueprints) {
        resultBlueprints.put(savedBlueprint.getName(), savedBlueprint);
    }
    return resultBlueprints.values();
}
Also used : BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) USER_MANAGED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.USER_MANAGED) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Service(org.springframework.stereotype.Service) ClusterTemplateService(com.sequenceiq.cloudbreak.service.template.ClusterTemplateService) Map(java.util.Map) BlueprintUpgradeOption(com.sequenceiq.cloudbreak.domain.BlueprintUpgradeOption) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Logger(org.slf4j.Logger) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) DEFAULT_DELETED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT_DELETED) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) DEFAULT(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint)

Example 48 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class DefaultClusterTemplateCache method defaultClusterTemplatesByNames.

public List<ClusterTemplate> defaultClusterTemplatesByNames(Collection<String> templateNamesMissingFromDb, Set<Blueprint> blueprints) {
    List<ClusterTemplate> defaultTemplates = new ArrayList<>();
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    User user = userService.getOrCreate(cloudbreakUser);
    Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
    boolean internalTenant = entitlementService.internalTenant(workspace.getTenant().getName());
    defaultClusterTemplateRequests().forEach((key, value) -> {
        if (templateNamesMissingFromDb.contains(key)) {
            String defaultTemplateJson = new String(Base64.getDecoder().decode(value));
            DefaultClusterTemplateV4Request defaultClusterTemplate = getDefaultClusterTemplate(defaultTemplateJson);
            if (internalClusterTemplateValidator.shouldPopulate(defaultClusterTemplate, internalTenant)) {
                ClusterTemplate clusterTemplate = defaultClusterTemplateV4RequestToClusterTemplateConverter.convert(defaultClusterTemplate);
                clusterTemplate.setWorkspace(workspace);
                Optional<Blueprint> blueprint = blueprints.stream().filter(e -> e.getName().equals(defaultClusterTemplate.getDistroXTemplate().getCluster().getBlueprintName())).findFirst();
                if (blueprint.isPresent()) {
                    clusterTemplate.setClouderaRuntimeVersion(blueprint.get().getStackVersion());
                }
                defaultTemplates.add(clusterTemplate);
            }
        }
    });
    return defaultTemplates;
}
Also used : Arrays(java.util.Arrays) FileReaderUtils.readFileFromClasspath(com.sequenceiq.cloudbreak.util.FileReaderUtils.readFileFromClasspath) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) CloudbreakRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService) InternalClusterTemplateValidator(com.sequenceiq.distrox.v1.distrox.service.InternalClusterTemplateValidator) Service(org.springframework.stereotype.Service) Map(java.util.Map) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Logger(org.slf4j.Logger) DefaultClusterTemplateV4RequestToClusterTemplateConverter(com.sequenceiq.cloudbreak.converter.v4.clustertemplate.DefaultClusterTemplateV4RequestToClusterTemplateConverter) Collection(java.util.Collection) Set(java.util.Set) UserService(com.sequenceiq.cloudbreak.service.user.UserService) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) IOException(java.io.IOException) DefaultClusterTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request) Collectors(java.util.stream.Collectors) File(java.io.File) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Json(com.sequenceiq.cloudbreak.common.json.Json) Base64(java.util.Base64) List(java.util.List) User(com.sequenceiq.cloudbreak.workspace.model.User) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) DefaultClusterTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ArrayList(java.util.ArrayList) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 49 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class StackOperationService method renewCertificate.

public FlowIdentifier renewCertificate(String stackName) {
    Workspace workspace = workspaceService.getForCurrentUser();
    Stack stack = stackService.getByNameInWorkspace(stackName, workspace.getId());
    return renewCertificate(stack.getId());
}
Also used : Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 50 with Workspace

use of com.sequenceiq.cloudbreak.workspace.model.Workspace in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method setup.

@Before
public void setup() throws CloudbreakImageNotFoundException {
    MockitoAnnotations.initMocks(this);
    when(stateContext.getMessageHeader(HEADERS.FLOW_PARAMETERS.name())).thenReturn(new FlowParameters("flowId", "usercrn", null));
    when(stateContext.getExtendedState()).thenReturn(extendedState);
    when(stateContext.getStateMachine()).thenReturn(stateMachine);
    when(stateMachine.getState()).thenReturn(state);
    when(extendedState.getVariables()).thenReturn(variables);
    when(runningFlows.getFlowChainId(anyString())).thenReturn("flowchainid");
    when(reactorEventFactory.createEvent(any(Map.class), any(Object.class))).thenReturn(new Event("dummy"));
    when(imageService.getImage(anyLong())).thenReturn(image);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(span);
    when(tracer.activateSpan(span)).thenReturn(scope);
    when(span.context()).thenReturn(spanContext);
    User user = new User();
    user.setUserId("horton@hortonworks.com");
    user.setUserCrn("testCrn");
    user.setUserName("Alma ur");
    Tenant tenant = new Tenant();
    tenant.setName("hortonworks");
    tenant.setId(1L);
    Workspace workspace = new Workspace();
    workspace.setId(1L);
    workspace.setTenant(tenant);
    Stack stack = new Stack();
    stack.setCreator(user);
    stack.setWorkspace(workspace);
    stack.setId(1L);
    stack.setRegion("region");
    stack.setAvailabilityZone("az");
    stack.setResourceCrn("crn:cdp:datalake:us-west-1:tenant:cluster:1234");
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    when(stackService.getById(anyLong())).thenReturn(stack);
    when(stackUtil.getCloudCredential(stack)).thenReturn(cloudCredential);
    variables.clear();
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) User(com.sequenceiq.cloudbreak.workspace.model.User) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Map(java.util.Map) HashMap(java.util.HashMap) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Before(org.junit.Before)

Aggregations

Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)75 User (com.sequenceiq.cloudbreak.workspace.model.User)26 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)17 Tenant (com.sequenceiq.cloudbreak.workspace.model.Tenant)12 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)7 Before (org.junit.Before)7 Test (org.junit.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)4 Json (com.sequenceiq.cloudbreak.common.json.Json)4 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)4 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)4 ClusterTemplate (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)4 HashSet (java.util.HashSet)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4