Search in sources :

Example 1 with AvailabilityZone

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

the class AwsPlatformResources method virtualMachines.

@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    CloudRegions regions = regions(cloudCredential, region, filters);
    Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
    Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
    for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
        cloudVmResponses.put(availabilityZone.value(), vmTypes.get(region));
        defaultCloudVmResponses.put(availabilityZone.value(), defaultVmTypes.get(region));
    }
    return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) HashMap(java.util.HashMap) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with AvailabilityZone

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

the class AzureTemplateBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    Configuration configuration = factoryBean.getObject();
    ReflectionTestUtils.setField(azureTemplateBuilder, "freemarkerConfiguration", configuration);
    ReflectionTestUtils.setField(azureTemplateBuilder, "armTemplatePath", templatePath);
    ReflectionTestUtils.setField(azureTemplateBuilder, "armTemplateParametersPath", "templates/parameters.ftl");
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, CORE_CUSTOM_DATA, InstanceGroupType.GATEWAY, GATEWAY_CUSTOM_DATA);
    groups = new ArrayList<>();
    stackName = "testStack";
    name = "master";
    List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
    InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
    Map<String, Object> params = new HashMap<>();
    params.put(CloudInstance.SUBNET_ID, "existingSubnet");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication, params);
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    security = new Security(rules, null);
    image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
    cloudContext = new CloudContext(7899L, "thisisaverylongazureresourcenamewhichneedstobeshortened", "dummy1", "dummy2", "test", Location.location(Region.region("EU"), new AvailabilityZone("availabilityZone")));
    azureCredentialView = new AzureCredentialView(cloudCredential("siq-haas"));
    azureStorageView = new AzureStorageView(azureCredentialView, cloudContext, azureStorage, null);
    azureSubnetStrategy = AzureSubnetStrategy.getAzureSubnetStrategy(FILL, Collections.singletonList("existingSubnet"), ImmutableMap.of("existingSubnet", 100));
    defaultTags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
    defaultTags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
    defaultTags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
    defaultTags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
    defaultTags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
    defaultTags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
    defaultTags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
    reset(azureUtils);
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Matchers.containsString(org.hamcrest.Matchers.containsString) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) AzureStorageView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStorageView) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Example 3 with AvailabilityZone

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

the class OpenStackPlatformResourcesTest method testVirtualMachines.

@Test
public void testVirtualMachines() {
    CloudCredential cloudCredential = new CloudCredential(0L, "name");
    OSClient osClient = mock(OSClient.class);
    String regionName = "region1";
    Set<String> regionsFromOpenStack = Sets.newHashSet(regionName);
    List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1"));
    Flavor flavor8GB = flavor(8192);
    when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient);
    when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack);
    when(openStackClient.getZones(osClient, regionName)).thenReturn(availabilityZones);
    when(openStackClient.getFlavors(osClient)).thenReturn((List) Collections.singletonList(flavor8GB));
    CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null);
    Assert.assertEquals(1, actual.getCloudVmResponses().get("zone1").size());
    Assert.assertEquals(1, actual.getDefaultCloudVmResponses().size());
    Assert.assertEquals("8.0", actual.getCloudVmResponses().get("zone1").iterator().next().getMetaData().getProperties().get("Memory"));
    Assert.assertNotNull(actual.getDefaultCloudVmResponses().get(regionName));
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) OSClient(org.openstack4j.api.OSClient) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Flavor(org.openstack4j.model.compute.Flavor) Test(org.junit.Test)

Example 4 with AvailabilityZone

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

the class OpenStackPlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    Set<String> regionsFromOpenStack = openStackClient.getRegion(cloudCredential);
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    for (String regionFromOpenStack : regionsFromOpenStack) {
        List<AvailabilityZone> availabilityZones = openStackClient.getZones(osClient, regionFromOpenStack);
        cloudRegions.put(region(regionFromOpenStack), availabilityZones);
        displayNames.put(region(regionFromOpenStack), regionFromOpenStack);
    }
    String defaultRegion = null;
    if (!cloudRegions.keySet().isEmpty()) {
        defaultRegion = ((StringType) cloudRegions.keySet().toArray()[0]).value();
    }
    CloudRegions regions = new CloudRegions(cloudRegions, displayNames, defaultRegion);
    LOGGER.info("openstack regions result: {}", regions);
    return regions;
}
Also used : HashMap(java.util.HashMap) Region(com.sequenceiq.cloudbreak.cloud.model.Region) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) List(java.util.List) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 5 with AvailabilityZone

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

the class OpenStackPlatformResources method gateways.

@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
        Set<CloudGateWay> cloudGateWays = new HashSet<>();
        List<? extends Router> routerList = osClient.networking().router().list();
        LOGGER.info("routers from openstack: {}", routerList);
        for (Router router : routerList) {
            CloudGateWay cloudGateWay = new CloudGateWay();
            cloudGateWay.setId(router.getId());
            cloudGateWay.setName(router.getName());
            Map<String, Object> properties = new HashMap<>();
            properties.put("tenantId", router.getTenantId());
            cloudGateWay.setProperties(properties);
            cloudGateWays.add(cloudGateWay);
        }
        for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
            resultCloudGateWayMap.put(availabilityZone.value(), cloudGateWays);
        }
    }
    CloudGateWays cloudGateWays = new CloudGateWays(resultCloudGateWayMap);
    LOGGER.info("openstack cloudgateway result: {}", cloudGateWays);
    return cloudGateWays;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Router(org.openstack4j.model.network.Router) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay) Region(com.sequenceiq.cloudbreak.cloud.model.Region) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)17 HashMap (java.util.HashMap)13 List (java.util.List)10 Region (com.sequenceiq.cloudbreak.cloud.model.Region)9 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)8 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 Cacheable (org.springframework.cache.annotation.Cacheable)5 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Test (org.junit.Test)4 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 IOException (java.io.IOException)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 Compute (com.google.api.services.compute.Compute)2 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudGateWay (com.sequenceiq.cloudbreak.cloud.model.CloudGateWay)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 Collections.singletonList (java.util.Collections.singletonList)2