Search in sources :

Example 11 with Template

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

the class TemplateDecoratorTest method testDecoratorWhenNoLocation.

@Test
public void testDecoratorWhenNoLocation() {
    String region = "region";
    String availibilityZone = "availabilityZone";
    String variant = "variant";
    String vmType = "vmType";
    Template template = new Template();
    Credential cloudCredential = mock(Credential.class);
    CloudVmTypes cloudVmTypes = new CloudVmTypes(singletonMap(region, emptySet()), emptyMap());
    when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
    when(locationService.location(region, availibilityZone)).thenReturn(null);
    Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
    Assert.assertNull(actual.getVolumeCount());
    Assert.assertNull(actual.getVolumeSize());
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.Test)

Example 12 with Template

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

the class TemplateDecoratorTest method testDecoratorWhenNoInstanceType.

@Test
public void testDecoratorWhenNoInstanceType() {
    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("missingVmType");
    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.assertNull(actual.getVolumeCount());
    Assert.assertNull(actual.getVolumeSize());
}
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 13 with Template

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

the class TemplateController method getPrivate.

@Override
public TemplateResponse getPrivate(String name) {
    IdentityUser user = authenticatedUserService.getCbUser();
    Template template = templateService.getPrivateTemplate(name, user);
    return convert(template);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 14 with Template

use of com.sequenceiq.cloudbreak.domain.Template 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 15 with Template

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

the class InstanceMetaDataToCloudInstanceConverter method convert.

@Override
public CloudInstance convert(InstanceMetaData metaDataEnity) {
    InstanceGroup group = metaDataEnity.getInstanceGroup();
    Template template = metaDataEnity.getInstanceGroup().getTemplate();
    StackAuthentication stackAuthentication = group.getStack().getStackAuthentication();
    InstanceStatus status = getInstanceStatus(metaDataEnity);
    InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEnity.getPrivateId(), status);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.getPublicKey(), stackAuthentication.getPublicKeyId(), stackAuthentication.getLoginUserName());
    Map<String, Object> params = new HashMap<>();
    params.put(CloudInstance.SUBNET_ID, metaDataEnity.getSubnetId());
    return new CloudInstance(metaDataEnity.getInstanceId(), instanceTemplate, instanceAuthentication, params);
}
Also used : StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

Template (com.sequenceiq.cloudbreak.domain.Template)25 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)5 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)5 Credential (com.sequenceiq.cloudbreak.domain.Credential)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Json (com.sequenceiq.cloudbreak.domain.json.Json)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)2 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)2 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)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 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)2