use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class UserService method findUserAndSetCrnIfExists.
private User findUserAndSetCrnIfExists(CloudbreakUser cloudbreakUser) {
try {
return transactionService.requiresNew(() -> {
Optional<User> userByIdAndTenantName = userRepository.findByTenantNameAndUserId(cloudbreakUser.getTenant(), cloudbreakUser.getUserId());
if (userByIdAndTenantName.isPresent()) {
User user = userByIdAndTenantName.get();
if (user.getUserCrn() == null) {
user.setUserCrn(cloudbreakUser.getUserCrn());
user = userRepository.save(user);
}
return user;
}
return null;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class WorkspaceService method getByIdForCurrentUser.
public Workspace getByIdForCurrentUser(Long id) {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
return get(id, user);
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class WorkspaceService method getForCurrentUser.
public Workspace getForCurrentUser() {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
return get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class StackCommonServiceTest method testStartInstancesInDefaultWorkspace.
@Test
public void testStartInstancesInDefaultWorkspace() {
Stack stack = new Stack();
stack.setType(StackType.WORKLOAD);
when(stackService.findStackByNameOrCrnAndWorkspaceId(STACK_CRN, WORKSPACE_ID)).thenReturn(Optional.of(stack));
CloudbreakUser cloudbreakUser = mock(CloudbreakUser.class);
when(cloudbreakUser.getUserCrn()).thenReturn("crn:cdp:" + Crn.Service.AUTOSCALE.getName() + ":us-west-1:altus:user:__internal__actor__");
when(restRequestThreadLocalService.getCloudbreakUser()).thenReturn(cloudbreakUser);
when(stackUtil.stopStartScalingEntitlementEnabled(stack)).thenReturn(true);
UpdateStackV4Request updateStackV4Request = new UpdateStackV4Request();
updateStackV4Request.setWithClusterEvent(true);
InstanceGroupAdjustmentV4Request instanceGroupAdjustmentV4Request = new InstanceGroupAdjustmentV4Request();
instanceGroupAdjustmentV4Request.setInstanceGroup("instanceGroup");
instanceGroupAdjustmentV4Request.setScalingAdjustment(5);
updateStackV4Request.setInstanceGroupAdjustment(instanceGroupAdjustmentV4Request);
when(regionAwareInternalCrnGeneratorFactory.autoscale()).thenReturn(regionAwareInternalCrnGenerator);
// Regular flow
underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, ScalingStrategy.STOPSTART_FALLBACK_TO_REGULAR);
verify(stackOperationService).updateNodeCountStartInstances(stack, updateStackV4Request.getInstanceGroupAdjustment(), true, ScalingStrategy.STOPSTART_FALLBACK_TO_REGULAR);
// Null scaling strategy
underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, null);
verify(stackOperationService).updateNodeCountStartInstances(stack, updateStackV4Request.getInstanceGroupAdjustment(), true, ScalingStrategy.STOPSTART);
// Status is set - Bad Request
updateStackV4Request.setStatus(StatusRequest.FULL_SYNC);
assertThrows(BadRequestException.class, () -> underTest.putStartInstancesInDefaultWorkspace(STACK_CRN, WORKSPACE_ID, updateStackV4Request, null));
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class ClusterTemplateV4RequestToClusterTemplateConverter method convert.
public ClusterTemplate convert(ClusterTemplateV4Request source) {
if (source.getDistroXTemplate() == null) {
throw new BadRequestException("The Datahub template cannot be null.");
}
if (StringUtils.isEmpty(source.getDistroXTemplate().getEnvironmentName())) {
throw new BadRequestException("The environmentName cannot be null.");
}
ClusterTemplate clusterTemplate = new ClusterTemplate();
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
clusterTemplate.setWorkspace(workspace);
StackV4Request stackV4Request = stackV4RequestConverter.convert(source.getDistroXTemplate());
stackV4Request.setType(StackType.TEMPLATE);
Stack stack = stackV4RequestToStackConverter.convert(stackV4Request);
prepareEmptyInstanceMetadata(stack);
clusterTemplate.setStackTemplate(stack);
clusterTemplate.setCloudPlatform(getCloudPlatform(source, stack));
clusterTemplate.setName(source.getName());
clusterTemplate.setDescription(source.getDescription());
clusterTemplate.setDatalakeRequired(DatalakeRequired.OPTIONAL);
clusterTemplate.setFeatureState(FeatureState.RELEASED);
clusterTemplate.setStatus(ResourceStatus.USER_MANAGED);
checkStackWhetherItsCapableOfProvidingCldrRuntimeVersion(stack);
clusterTemplate.setClouderaRuntimeVersion(stack.getCluster().getBlueprint().getStackVersion());
if (source.getType() == null) {
clusterTemplate.setType(ClusterTemplateV4Type.OTHER);
} else {
clusterTemplate.setType(source.getType());
}
return clusterTemplate;
}
Aggregations