use of com.sequenceiq.cloudbreak.domain.Network in project cloudbreak by hortonworks.
the class StackValidationRequestToStackValidationConverter method validateNetwork.
private void validateNetwork(Long networkId, NetworkRequest networkRequest, StackValidation stackValidation) {
SpecialParameters specialParameters = cloudParameterCache.getPlatformParameters().get(Platform.platform(stackValidation.getCredential().cloudPlatform())).specialParameters();
if (networkId != null) {
Network network = networkService.get(networkId);
stackValidation.setNetwork(network);
} else if (networkRequest != null) {
Network network = conversionService.convert(networkRequest, Network.class);
stackValidation.setNetwork(network);
} else if (specialParameters.getSpecialParameters().get(PlatformParametersConsts.NETWORK_IS_MANDATORY)) {
throw new BadRequestException("Network is not configured for the validation request!");
}
}
use of com.sequenceiq.cloudbreak.domain.Network in project cloudbreak by hortonworks.
the class NetworkRequestToNetworkConverter method convert.
@Override
public Network convert(NetworkRequest source) {
Network network = new Network();
if (Strings.isNullOrEmpty(source.getName())) {
network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
} else {
network.setName(source.getName());
}
network.setDescription(source.getDescription());
network.setSubnetCIDR(source.getSubnetCIDR());
network.setStatus(ResourceStatus.USER_MANAGED);
network.setCloudPlatform(source.getCloudPlatform());
Map<String, Object> parameters = source.getParameters();
if (parameters != null && !parameters.isEmpty()) {
try {
network.setAttributes(new Json(parameters));
} catch (JsonProcessingException ignored) {
throw new BadRequestException("Invalid parameters");
}
}
if (source.getTopologyId() != null) {
network.setTopology(topologyService.getById(source.getTopologyId()));
}
return network;
}
use of com.sequenceiq.cloudbreak.domain.Network in project cloudbreak by hortonworks.
the class StackDecorator method prepareDomainIfDefined.
private void prepareDomainIfDefined(Stack subject, StackRequest request, IdentityUser user) {
if (subject.getNetwork() != null) {
Network network = subject.getNetwork();
if (network.getId() == null) {
network.setPublicInAccount(subject.isPublicInAccount());
network.setCloudPlatform(getCloudPlatform(subject, request, network.cloudPlatform()));
network = networkService.create(user, network);
}
subject.setNetwork(network);
}
if (subject.getCredential() != null) {
Credential credentialForStack = subject.getCredential();
if (credentialForStack.getId() == null) {
credentialForStack.setPublicInAccount(subject.isPublicInAccount());
credentialForStack.setCloudPlatform(getCloudPlatform(subject, request, credentialForStack.cloudPlatform()));
credentialForStack = credentialService.create(user, credentialForStack);
}
subject.setCredential(credentialForStack);
}
}
use of com.sequenceiq.cloudbreak.domain.Network 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