Search in sources :

Example 21 with Network

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

the class AzureTemplateBuilderTest method buildWithPublicIpAndFirewall.

@Test
public void buildWithPublicIpAndFirewall() {
    // GIVEN
    Network network = new Network(new Subnet("testSubnet"));
    when(azureUtils.isPrivateIp(any())).then(invocation -> false);
    when(azureUtils.isNoSecurityGroups(any())).then(invocation -> false);
    when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
    Map<String, String> parameters = new HashMap<>();
    parameters.put("persistentStorage", "persistentStorageTest");
    parameters.put("attachedStorageOption", "attachedStorageOptionTest");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
    // WHEN
    when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
    when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
    String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
    // THEN
    gson.fromJson(templateString, Map.class);
    assertThat(templateString, containsString("publicIPAddress"));
    assertThat(templateString, containsString("networkSecurityGroups"));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 22 with Network

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

the class ParameterGenerator method createCloudStack.

public CloudStack createCloudStack() {
    List<Group> groups = new ArrayList<>();
    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");
    Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
    Subnet subnet = new Subnet("10.0.0.0/24");
    Network network = new Network(subnet);
    network.putParameter("publicNetId", "028ffc0c-63c5-4ca0-802a-3ac753eaf76c");
    return new CloudStack(groups, network, image, new HashMap<>(), new HashMap<>(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 23 with Network

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

the class StackToCloudStackConverter method buildNetwork.

private Network buildNetwork(Stack stack) {
    com.sequenceiq.cloudbreak.domain.Network stackNetwork = stack.getNetwork();
    Network result = null;
    if (stackNetwork != null) {
        Subnet subnet = new Subnet(stackNetwork.getSubnetCIDR());
        Json attributes = stackNetwork.getAttributes();
        Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
        result = new Network(subnet, params);
    }
    return result;
}
Also used : Network(com.sequenceiq.cloudbreak.cloud.model.Network) Json(com.sequenceiq.cloudbreak.domain.json.Json) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet)

Example 24 with Network

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

the class GcpNetworkResourceBuilder method build.

@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception {
    if (!isExistingNetwork(network)) {
        Compute compute = context.getCompute();
        String projectId = context.getProjectId();
        com.google.api.services.compute.model.Network gcpNetwork = new com.google.api.services.compute.model.Network();
        gcpNetwork.setName(resource.getName());
        gcpNetwork.setAutoCreateSubnetworks(false);
        Insert networkInsert = compute.networks().insert(projectId, gcpNetwork);
        try {
            Operation operation = networkInsert.execute();
            if (operation.getHttpErrorStatusCode() != null) {
                throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
            }
            context.putParameter(NETWORK_NAME, resource.getName());
            return createOperationAwareCloudResource(resource, operation);
        } catch (GoogleJsonResponseException e) {
            throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
        }
    }
    context.putParameter(NETWORK_NAME, resource.getName());
    return new Builder().cloudResource(resource).persistent(false).build();
}
Also used : Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) Operation(com.google.api.services.compute.model.Operation) Insert(com.google.api.services.compute.Compute.Networks.Insert) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Compute(com.google.api.services.compute.Compute) GcpStackUtil.isExistingNetwork(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.isExistingNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)

Example 25 with Network

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

the class StackToCloudStackConverter method convert.

public CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances) {
    Image image = null;
    List<Group> instanceGroups = buildInstanceGroups(stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), deleteRequestedInstances);
    try {
        image = imageService.getImage(stack.getId());
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info(e.getMessage());
    }
    Network network = buildNetwork(stack);
    StackTemplate stackTemplate = componentConfigProvider.getStackTemplate(stack.getId());
    InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
    String template = null;
    if (stackTemplate != null) {
        template = stackTemplate.getTemplate();
    }
    return new CloudStack(instanceGroups, network, image, stack.getParameters(), getUserDefinedTags(stack), template, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Aggregations

Network (com.sequenceiq.cloudbreak.cloud.model.Network)39 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)34 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)34 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)34 HashMap (java.util.HashMap)34 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)31 Test (org.junit.Test)31 Matchers.containsString (org.hamcrest.Matchers.containsString)19 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)17 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)14 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 Vpc (com.amazonaws.services.ec2.model.Vpc)14 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)14 Location (com.sequenceiq.cloudbreak.cloud.model.Location)14 ArrayList (java.util.ArrayList)4 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)2