Search in sources :

Example 46 with Group

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

the class HeatTemplateBuilderTest method setup.

@Before
public void setup() throws IOException, TemplateException {
    initMocks(this);
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    Configuration configuration = factoryBean.getObject();
    ReflectionTestUtils.setField(heatTemplateBuilder, "freemarkerConfiguration", configuration);
    ReflectionTestUtils.setField(heatTemplateBuilder, "openStackHeatTemplatePath", templatePath);
    stackName = "testStack";
    groups = new ArrayList<>(1);
    String 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);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    Security security = new Security(rules, null);
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    Map<String, String> tags = new HashMap<>();
    tags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
    tags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
    tags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
    tags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
    tags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
    tags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
    tags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
    when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(tags);
    image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "url", "default", null);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) 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) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) 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) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Example 47 with Group

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

the class OpenStackFlavorVerifier method flavorsExist.

public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) {
    if (instanceGroups == null) {
        throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null");
    }
    List<? extends Flavor> flavors = osClient.compute().flavors().list();
    if (flavors == null || flavors.isEmpty()) {
        throw new CloudConnectorException("No flavor found on OpenStack");
    }
    Set<String> notFoundFlavors = new HashSet<>();
    for (Group instanceGroup : instanceGroups) {
        String instanceType = instanceGroup.getReferenceInstanceConfiguration().getTemplate().getFlavor();
        boolean found = false;
        for (Flavor flavor : flavors) {
            if (flavor.getName().equalsIgnoreCase(instanceType)) {
                found = true;
                break;
            }
        }
        if (!found) {
            notFoundFlavors.add(instanceType);
        }
    }
    if (!notFoundFlavors.isEmpty()) {
        LOGGER.warn("Not found flavors: {}", notFoundFlavors);
        throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors));
    }
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Flavor(org.openstack4j.model.compute.Flavor) HashSet(java.util.HashSet)

Example 48 with Group

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

the class OpenStackGroupView method getFlatNovaView.

public List<NovaInstanceView> getFlatNovaView() {
    List<NovaInstanceView> novaInstances = new ArrayList<>();
    for (Group group : groups) {
        for (CloudInstance instance : group.getInstances()) {
            NovaInstanceView novaInstance = new NovaInstanceView(stackName, instance.getTemplate(), group.getType(), tags, group.getLoginUserName());
            novaInstances.add(novaInstance);
        }
    }
    return novaInstances;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 49 with Group

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

the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit24Vpc.

@Test
public void testFindNonOverLappingCIDRWit24Vpc() {
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    Map<String, Object> networkParameters = new HashMap<>();
    networkParameters.put("vpcId", "vpc-12345678");
    networkParameters.put("internetGatewayId", "igw-12345678");
    Network network = new Network(new Subnet(null), networkParameters);
    CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudContext cloudContext = mock(CloudContext.class);
    Location location = mock(Location.class);
    Vpc vpc = mock(Vpc.class);
    DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
    AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
    com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
    DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudContext.getLocation()).thenReturn(location);
    when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
    when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
    when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
    when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
    when(vpc.getCidrBlock()).thenReturn("10.0.0.0/24");
    when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
    when(subnetsResult.getSubnets()).thenReturn(singletonList(subnet1));
    when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/24");
    thrown.expect(CloudConnectorException.class);
    thrown.expectMessage("The selected VPC has to be in a bigger CIDR range than /24");
    underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Vpc(com.amazonaws.services.ec2.model.Vpc) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Test(org.junit.Test)

Example 50 with Group

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

the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit20Vpc2.

@Test
public void testFindNonOverLappingCIDRWit20Vpc2() {
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    Map<String, Object> networkParameters = new HashMap<>();
    networkParameters.put("vpcId", "vpc-12345678");
    networkParameters.put("internetGatewayId", "igw-12345678");
    Network network = new Network(new Subnet(null), networkParameters);
    CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudContext cloudContext = mock(CloudContext.class);
    Location location = mock(Location.class);
    Vpc vpc = mock(Vpc.class);
    DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
    AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
    com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
    com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
    com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
    com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
    DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudContext.getLocation()).thenReturn(location);
    when(cloudContext.getName()).thenReturn(new String(new byte[] { 16 }));
    when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
    when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
    when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
    when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
    when(vpc.getCidrBlock()).thenReturn("10.0.0.0/20");
    when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
    when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4));
    when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/24");
    when(subnet2.getCidrBlock()).thenReturn("10.0.1.0/24");
    when(subnet3.getCidrBlock()).thenReturn("10.0.2.0/24");
    when(subnet4.getCidrBlock()).thenReturn("10.0.3.0/24");
    String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
    Assert.assertEquals("10.0.4.0/24", cidr);
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Vpc(com.amazonaws.services.ec2.model.Vpc) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Test(org.junit.Test)

Aggregations

Group (com.sequenceiq.cloudbreak.cloud.model.Group)62 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)37 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)36 Test (org.junit.Test)36 Network (com.sequenceiq.cloudbreak.cloud.model.Network)35 HashMap (java.util.HashMap)35 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)33 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)33 Matchers.containsString (org.hamcrest.Matchers.containsString)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)17 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)15 Vpc (com.amazonaws.services.ec2.model.Vpc)15 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)15 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 Location (com.sequenceiq.cloudbreak.cloud.model.Location)14 ArrayList (java.util.ArrayList)14 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9