Search in sources :

Example 31 with Credential

use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.

the class CredentialServiceTest method init.

@Before
public void init() throws Exception {
    doNothing().when(authorizationService).hasWritePermission(any());
    doNothing().when(notificationSender).send(any());
    when(credentialAdapter.init(any(Credential.class))).then(invocation -> invocation.getArgumentAt(0, Credential.class));
    credentialToModify = new Credential();
    credentialToModify.setId(1L);
    credentialToModify.setCloudPlatform(PLATFORM);
    originalTopology = new Topology();
    credentialToModify.setTopology(originalTopology);
    originalDescription = "orig-desc";
    credentialToModify.setDescription(originalDescription);
    originalAttributes = new Json("test");
    credentialToModify.setAttributes(originalAttributes);
    when(credentialRepository.findByNameInUser(anyString(), anyString())).thenReturn(credentialToModify);
    when(credentialRepository.findOneByName(anyString(), anyString())).thenReturn(credentialToModify);
    when(credentialRepository.save(any(Credential.class))).then(invocation -> invocation.getArgumentAt(0, Credential.class));
    user = new IdentityUser("asef", "asdf", "asdf", null, "ASdf", "asdf", new Date());
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Credential(com.sequenceiq.cloudbreak.domain.Credential) Topology(com.sequenceiq.cloudbreak.domain.Topology) Json(com.sequenceiq.cloudbreak.domain.json.Json) Date(java.util.Date) Before(org.junit.Before)

Example 32 with Credential

use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.

the class CredentialServiceTest method testRetrieveAccountCredentialsWhenUserIsAdmin.

@Test
public void testRetrieveAccountCredentialsWhenUserIsAdmin() {
    IdentityUser user = mock(IdentityUser.class);
    Set<String> platforms = Sets.newHashSet("AWS");
    Credential credential = new Credential();
    credential.setCloudPlatform("AWS");
    when(user.getRoles()).thenReturn(Collections.singletonList(IdentityUserRole.fromString("ADMIN")));
    when(user.getAccount()).thenReturn("account");
    when(accountPreferencesService.enabledPlatforms()).thenReturn(platforms);
    when(credentialRepository.findAllInAccountAndFilterByPlatforms(user.getAccount(), platforms)).thenReturn(Sets.newHashSet(credential));
    Set<Credential> actual = credentialService.retrieveAccountCredentials(user);
    assertEquals("AWS", actual.stream().findFirst().get().cloudPlatform());
    verify(credentialRepository, times(1)).findAllInAccountAndFilterByPlatforms("account", platforms);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Credential(com.sequenceiq.cloudbreak.domain.Credential) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 33 with Credential

use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.

the class TemplateDecoratorTest method testDecorator.

@Test
public void testDecorator() {
    String vmType = "vmType";
    String platform1 = "platform";
    String volumeType = "volumeType";
    String region = "region";
    String availibilityZone = "availabilityZone";
    String variant = "variant";
    Credential cloudCredential = mock(Credential.class);
    Template template = new Template();
    template.setInstanceType(vmType);
    template.setCloudPlatform(platform1);
    template.setVolumeType(volumeType);
    Platform platform = Platform.platform(platform1);
    int minimumSize = 10;
    int maximumSize = 100;
    int minimumNumber = 1;
    int maximumNumber = 5;
    VolumeParameterConfig config = new VolumeParameterConfig(VolumeParameterType.MAGNETIC, minimumSize, maximumSize, minimumNumber, maximumNumber);
    VmTypeMeta vmTypeMeta = new VmTypeMeta();
    vmTypeMeta.setMagneticConfig(config);
    Map<Platform, Map<String, VolumeParameterType>> diskMappings = newHashMap();
    diskMappings.put(platform, singletonMap(volumeType, VolumeParameterType.MAGNETIC));
    PlatformDisks platformDisk = new PlatformDisks(emptyMap(), emptyMap(), diskMappings, emptyMap());
    CloudVmTypes cloudVmTypes = new CloudVmTypes();
    Map<String, Set<VmType>> region1 = singletonMap(region, Collections.singleton(VmType.vmTypeWithMeta(vmType, vmTypeMeta, true)));
    cloudVmTypes.setCloudVmResponses(region1);
    when(cloudParameterService.getDiskTypes()).thenReturn(platformDisk);
    when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
    when(locationService.location(region, availibilityZone)).thenReturn(region);
    Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
    Assert.assertEquals(maximumNumber, actual.getVolumeCount().longValue());
    Assert.assertEquals(maximumSize, actual.getVolumeSize().longValue());
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Credential(com.sequenceiq.cloudbreak.domain.Credential) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) Template(com.sequenceiq.cloudbreak.domain.Template) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Matchers.anyMap(org.mockito.Matchers.anyMap) Test(org.junit.Test)

Example 34 with Credential

use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.

the class StackValidationRequestToStackValidationConverter method validateCredential.

private void validateCredential(StackValidationRequest stackValidationRequest, StackValidation stackValidation) {
    if (stackValidationRequest.getCredentialId() != null) {
        Credential credential = credentialService.get(stackValidationRequest.getCredentialId());
        stackValidation.setCredential(credential);
    } else if (stackValidationRequest.getCredentialName() != null) {
        Credential credential = credentialService.get(stackValidationRequest.getCredentialName(), stackValidationRequest.getAccount());
        stackValidation.setCredential(credential);
    } else if (stackValidationRequest.getCredential() != null) {
        Credential credential = conversionService.convert(stackValidationRequest.getCredential(), Credential.class);
        stackValidation.setCredential(credential);
    } else {
        throw new BadRequestException("Credential is not configured for the validation request!");
    }
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 35 with Credential

use of com.sequenceiq.cloudbreak.domain.Credential 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)

Aggregations

Credential (com.sequenceiq.cloudbreak.domain.Credential)44 Test (org.junit.Test)14 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)8 AccessDeniedException (org.springframework.security.access.AccessDeniedException)8 Json (com.sequenceiq.cloudbreak.domain.json.Json)7 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)6 Template (com.sequenceiq.cloudbreak.domain.Template)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 FileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration)3 FileSystemScriptConfig (com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemScriptConfig)3 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Transactional (javax.transaction.Transactional)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 GcsFileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.GcsFileSystemConfiguration)2 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)2 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)2 RecipeScript (com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript)2