use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.
the class TemplateService method getPublicTemplate.
public Template getPublicTemplate(String name, IdentityUser user) {
Template template = templateRepository.findOneByName(name, user.getAccount());
if (template == null) {
throw new NotFoundException(String.format(TEMPLATE_NOT_FOUND_MSG, name));
}
authorizationService.hasReadPermission(template);
return template;
}
use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.
the class TemplateService method create.
@Transactional(TxType.NEVER)
public Template create(IdentityUser user, Template template) {
LOGGER.debug("Creating template: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
Template savedTemplate;
template.setOwner(user.getUserId());
template.setAccount(user.getAccount());
try {
savedTemplate = templateRepository.save(template);
} catch (Exception ex) {
throw new DuplicateKeyValueException(APIResourceType.TEMPLATE, template.getName(), ex);
}
return savedTemplate;
}
use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.
the class UsageService method openUsagesForStack.
public void openUsagesForStack(Stack stack) {
LocalDateTime ldt = LocalDateTime.now();
List<CloudbreakUsage> usages = Lists.newArrayList();
for (InstanceGroup ig : stack.getInstanceGroups()) {
Template template = ig.getTemplate();
String instanceType = template == null ? "undefined" : template.getInstanceType();
String groupName = ig.getGroupName();
Integer instanceNum = ig.getNodeCount();
usages.add(usageGeneratorService.openNewUsage(stack, instanceType, instanceNum, groupName, ldt));
}
usageRepository.save(usages);
}
use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.
the class InstanceGroupToInstanceGroupDetailsConverter method convert.
@Override
public InstanceGroupDetails convert(InstanceGroup source) {
InstanceGroupDetails instanceGroupDetails = new InstanceGroupDetails();
instanceGroupDetails.setGroupName(source.getGroupName());
instanceGroupDetails.setGroupType(source.getInstanceGroupType().name());
instanceGroupDetails.setNodeCount(source.getNodeCount());
Template template = source.getTemplate();
if (template != null) {
instanceGroupDetails.setInstanceType(source.getTemplate().getInstanceType());
instanceGroupDetails.setVolumeType(source.getTemplate().getVolumeType());
instanceGroupDetails.setVolumeSize(source.getTemplate().getVolumeSize());
instanceGroupDetails.setVolumeCount(source.getTemplate().getVolumeCount());
}
instanceGroupDetails.setSecurityGroup(conversionService.convert(source.getSecurityGroup(), SecurityGroupDetails.class));
return instanceGroupDetails;
}
use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.
the class UserResourceCheck method hasResources.
@Transactional(readOnly = true)
public boolean hasResources(IdentityUser admin, String userId) {
IdentityUser user = userDetailsService.getDetails(userId, UserFilterField.USERID);
LOGGER.info("{} / {} checks resources of {}", admin.getUserId(), admin.getUsername(), userId);
String errorMessage = null;
if (!admin.getRoles().contains(IdentityUserRole.ADMIN)) {
errorMessage = "Forbidden: user (%s) is not authorized for this operation on %s";
}
if (!admin.getAccount().equals(user.getAccount())) {
errorMessage = "Forbidden: admin (%s) and user (%s) are not under the same account.";
}
if (!Strings.isNullOrEmpty(errorMessage)) {
throw new AccessDeniedException(String.format(errorMessage, admin.getUsername(), user.getUsername()));
}
Set<Template> templates = templateRepository.findForUser(user.getUserId());
Set<Credential> credentials = credentialRepository.findForUser(user.getUserId());
Set<Blueprint> blueprints = blueprintRepository.findForUser(user.getUserId());
Set<Network> networks = networkRepository.findForUser(user.getUserId());
Set<Stack> stacks = stackRepository.findForUser(user.getUserId());
return !(stacks.isEmpty() && templates.isEmpty() && credentials.isEmpty() && blueprints.isEmpty() && networks.isEmpty());
}
Aggregations