Search in sources :

Example 11 with Network

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!");
    }
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) SpecialParameters(com.sequenceiq.cloudbreak.api.model.SpecialParameters)

Example 12 with Network

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;
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 13 with 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);
    }
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) Network(com.sequenceiq.cloudbreak.domain.Network)

Example 14 with Network

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());
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Credential(com.sequenceiq.cloudbreak.domain.Credential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Template(com.sequenceiq.cloudbreak.domain.Template) Stack(com.sequenceiq.cloudbreak.domain.Stack) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Network(com.sequenceiq.cloudbreak.domain.Network) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Network (com.sequenceiq.cloudbreak.domain.Network)14 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)5 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 Credential (com.sequenceiq.cloudbreak.domain.Credential)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SpecialParameters (com.sequenceiq.cloudbreak.api.model.SpecialParameters)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)1 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)1 Resource (com.sequenceiq.cloudbreak.domain.Resource)1 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)1 Template (com.sequenceiq.cloudbreak.domain.Template)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 Transactional (org.springframework.transaction.annotation.Transactional)1