Search in sources :

Example 11 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform 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 12 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class AbstractInstanceConnector method stop.

@Override
public List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
    CloudContext cloudContext = ac.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, ac, null, resources, false);
    // compute
    return computeResourceService.stopInstances(context, ac, resources, vms);
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Example 13 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class AbstractResourceConnector method terminate.

@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext auth, CloudStack stack, List<CloudResource> cloudResources) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), cloudResources, false);
    // compute
    List<CloudResourceStatus> cloudResourceStatuses = computeResourceService.deleteResources(context, auth, cloudResources, false);
    // group
    List<CloudResourceStatus> groupStatuses = groupResourceService.deleteResources(context, auth, cloudResources, stack.getNetwork(), false);
    cloudResourceStatuses.addAll(groupStatuses);
    // network
    List<CloudResourceStatus> networkStatuses = networkResourceService.deleteResources(context, auth, cloudResources, stack.getNetwork(), false);
    cloudResourceStatuses.addAll(networkStatuses);
    return cloudResourceStatuses;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Example 14 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class AbstractResourceConnector method upscale.

@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources) {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, true);
    // network
    context.addNetworkResources(networkResourceService.getNetworkResources(platform, resources));
    Group scalingGroup = getScalingGroup(getGroup(stack.getGroups(), getGroupName(stack)));
    // group
    context.addGroupResources(scalingGroup.getName(), groupResourceService.getGroupResources(platform, resources));
    // compute
    return computeResourceService.buildResourcesForUpscale(context, auth, Collections.singletonList(scalingGroup), stack.getImage(), stack.getTags());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Example 15 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class AbstractResourceConnector method downscale.

@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, List<CloudResource> resourcesToRemove) {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, false);
    // compute
    return computeResourceService.deleteResources(context, auth, resourcesToRemove, true);
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Aggregations

Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)26 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)7 Map (java.util.Map)7 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)6 HashMap (java.util.HashMap)6 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)5 Collection (java.util.Collection)5 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)4 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)4 Set (java.util.Set)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 SpecialParameters (com.sequenceiq.cloudbreak.api.model.SpecialParameters)2 SpecialParametersJson (com.sequenceiq.cloudbreak.api.model.SpecialParametersJson)2 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)2 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)2 PlatformOrchestrators (com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2