Search in sources :

Example 6 with NetworkRequest

use of com.sequenceiq.cloudbreak.api.model.NetworkRequest in project cloudbreak by hortonworks.

the class AwsCreateVpcNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "vpcStackName", "vpcName", "existingSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-stack") String vpcStackName, @Optional("it-vpc") String vpcName, boolean existingSubnet) {
    AmazonCloudFormationClient client = new AmazonCloudFormationClient();
    client.setRegion(RegionUtils.getRegion(regionName));
    Map<String, Object> networkMap = new HashMap<>();
    String vpcCreationJson = existingSubnet ? "public_vpc_with_subnet.json" : "public_vpc_wihout_subnet.json";
    try (InputStream vpcJsonInputStream = getClass().getResourceAsStream("/cloudformation/" + vpcCreationJson)) {
        String vpcCFTemplateString = IOUtils.toString(vpcJsonInputStream);
        CreateStackRequest stackRequest = createStackRequest(vpcStackName, vpcName, vpcCFTemplateString);
        client.createStack(stackRequest);
        List<Output> outputForRequest = getOutputForRequest(vpcStackName, client);
        if (existingSubnet) {
            networkMap.put("vpcId", outputForRequest.get(0).getOutputValue());
            networkMap.put("subnetId", outputForRequest.get(1).getOutputValue());
        } else {
            networkMap.put("vpcId", outputForRequest.get(1).getOutputValue());
            networkMap.put("internetGatewayId", outputForRequest.get(0).getOutputValue());
        }
    } catch (IOException e) {
        LOGGER.error("can't read vpc cloudformation template file");
        throw new RuntimeException(e);
    }
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    networkRequest.setParameters(networkMap);
    if (!existingSubnet) {
        networkRequest.setSubnetCIDR("10.0.0.0/24");
    }
    networkRequest.setCloudPlatform("AWS");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) Output(com.amazonaws.services.cloudformation.model.Output) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) IOException(java.io.IOException) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 7 with NetworkRequest

use of com.sequenceiq.cloudbreak.api.model.NetworkRequest in project cloudbreak by hortonworks.

the class OpenStackNetworkCreationTest method testOpenstackNetworkCreation.

@Test
@Parameters({ "networkName", "subnetCIDR", "publicNetId" })
public void testOpenstackNetworkCreation(@Optional("it-openstack-network") String networkName, @Optional("10.0.36.0/24") String subnetCIDR, @Optional("") String publicNetId) {
    // GIVEN
    publicNetId = getPublicNetId(publicNetId, defaultPublicNetId);
    // WHEN
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setDescription("OpenStack network for integration testing");
    networkRequest.setName(networkName);
    networkRequest.setSubnetCIDR(subnetCIDR);
    Map<String, Object> map = new HashMap<>();
    map.put("publicNetId", publicNetId);
    networkRequest.setParameters(map);
    networkRequest.setCloudPlatform("OPENSTACK");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    // THEN
    Assert.assertNotNull(id);
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : HashMap(java.util.HashMap) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

NetworkRequest (com.sequenceiq.cloudbreak.api.model.NetworkRequest)7 Parameters (org.testng.annotations.Parameters)6 Test (org.testng.annotations.Test)6 HashMap (java.util.HashMap)5 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)2 Azure (com.microsoft.azure.management.Azure)2 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)2 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)1 CreateStackRequest (com.amazonaws.services.cloudformation.model.CreateStackRequest)1 Output (com.amazonaws.services.cloudformation.model.Output)1 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 HttpTransport (com.google.api.client.http.HttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Compute (com.google.api.services.compute.Compute)1 Builder (com.google.api.services.compute.Compute.Builder)1 Networks (com.google.api.services.compute.Compute.Networks)1 Insert (com.google.api.services.compute.Compute.Subnetworks.Insert)1 Network (com.google.api.services.compute.model.Network)1 Operation (com.google.api.services.compute.model.Operation)1