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();
}
}
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();
}
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;
}
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());
}
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();
}
Aggregations