Search in sources :

Example 1 with NetworkRequest

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

the class MockNetworkCreationTest method testGcpTemplateCreation.

@Test
@Parameters({ "networkName", "subnetCIDR" })
public void testGcpTemplateCreation(@Optional("it-mock-network") String networkName, @Optional("10.0.36.0/24") String subnetCIDR) {
    // GIVEN
    // WHEN
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setDescription("Mock network for integration testing");
    networkRequest.setName(networkName);
    networkRequest.setSubnetCIDR(subnetCIDR);
    networkRequest.setCloudPlatform("MOCK");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    // THEN
    Assert.assertNotNull(id);
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with NetworkRequest

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

the class AzureRmUseAnExistingSubnetInAnExistingVpcNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "resourceGroupName", "vpcName", "vpcSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-resource-group") String resourceGroupName, @Optional("it-vpc") String vpcName, @Optional("it-vpc-subnet") String vpcSubnet) {
    ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(defaultAccesKey, defaultTenantId, defaultSecretKey, null);
    Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(defaultSubscriptionId);
    azure.networks().define(vpcName).withRegion(regionName).withNewResourceGroup(resourceGroupName).withAddressSpace("10.0.0.0/16").withSubnet(vpcSubnet, "10.0.0.0/16").create();
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    Map<String, Object> map = new HashMap<>();
    map.put("networkId", vpcName);
    map.put("subnetId", vpcSubnet);
    map.put("resourceGroupName", resourceGroupName);
    networkRequest.setParameters(map);
    networkRequest.setCloudPlatform("AZURE");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : Azure(com.microsoft.azure.management.Azure) HashMap(java.util.HashMap) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 3 with NetworkRequest

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

the class GcpCreateVirtualNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "resourceGroupName", "vpcName", "vpcSubnet", "subnetCIDR", "networkType" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, @Optional("europe-west1") String subnetRegion, @Optional("it-vpc") String vpcName, @Optional("it-vpc-subnet") String vpcSubnet, @Optional("10.0.36.0/24") String subnetCIDR, NetworkType networkType) throws Exception {
    String serviceAccountPrivateKey = ResourceUtil.readBase64EncodedContentFromResource(applicationContext, defaultP12File);
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), new ByteArrayInputStream(Base64.decodeBase64(serviceAccountPrivateKey)), "notasecret", "privatekey", "notasecret");
    JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    GoogleCredential googleCredential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(defaultServiceAccountId).setServiceAccountScopes(Collections.singletonList(ComputeScopes.COMPUTE)).setServiceAccountPrivateKey(privateKey).build();
    Compute compute = new Builder(httpTransport, jsonFactory, null).setApplicationName(defaultName).setHttpRequestInitializer(googleCredential).build();
    Network gcpNetwork = new Network();
    gcpNetwork.setName(vpcName);
    if (!LAGACY_NETWORK.equals(networkType)) {
        gcpNetwork.setAutoCreateSubnetworks(false);
    }
    Networks.Insert networkInsert = compute.networks().insert(defaultProjectId, gcpNetwork);
    Operation networkInsertResponse = networkInsert.execute();
    if (networkInsertResponse.getHttpErrorStatusCode() != null) {
        throw new IllegalStateException("gcp network operation failed: " + networkInsertResponse.getHttpErrorMessage());
    }
    waitOperation(compute, networkInsertResponse);
    if (EXISTING_SUBNET_IN_EXISTING_NETWORK.equals(networkType)) {
        Subnetwork gcpSubnet = new Subnetwork();
        gcpSubnet.setName(vpcSubnet);
        gcpSubnet.setIpCidrRange(subnetCIDR);
        gcpSubnet.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", defaultProjectId, vpcName));
        Insert subNetworkInsert = compute.subnetworks().insert(defaultProjectId, subnetRegion, gcpSubnet);
        Operation subNetInsertResponse = subNetworkInsert.execute();
        if (subNetInsertResponse.getHttpErrorStatusCode() != null) {
            throw new IllegalStateException("gcp subnetwork operation failed: " + subNetInsertResponse.getHttpErrorMessage());
        }
    }
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    if (NEW_SUBNET_IN_EXISTING_NETWORK.equals(networkType)) {
        networkRequest.setSubnetCIDR(subnetCIDR);
    }
    Map<String, Object> map = new HashMap<>();
    map.put("networkId", vpcName);
    if (EXISTING_SUBNET_IN_EXISTING_NETWORK.equals(networkType)) {
        map.put("subnetId", vpcSubnet);
    }
    networkRequest.setParameters(map);
    networkRequest.setCloudPlatform("GCP");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : Networks(com.google.api.services.compute.Compute.Networks) PrivateKey(java.security.PrivateKey) Subnetwork(com.google.api.services.compute.model.Subnetwork) HashMap(java.util.HashMap) Builder(com.google.api.services.compute.Compute.Builder) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Operation(com.google.api.services.compute.model.Operation) Insert(com.google.api.services.compute.Compute.Subnetworks.Insert) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) ByteArrayInputStream(java.io.ByteArrayInputStream) Compute(com.google.api.services.compute.Compute) Network(com.google.api.services.compute.model.Network) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with NetworkRequest

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

the class NetworkV2RequestToNetworkRequestConverter method convert.

@Override
public NetworkRequest convert(NetworkV2Request source) {
    NetworkRequest network = new NetworkRequest();
    network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
    network.setSubnetCIDR(source.getSubnetCIDR());
    network.setParameters(source.getParameters());
    return network;
}
Also used : NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest)

Example 5 with NetworkRequest

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

the class AzureUseAnExistingSubnetInAnExistingVpcNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "resourceGroupName", "vpcName", "vpcSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-resource-group") String resourceGroupName, @Optional("it-vpc") String vpcName, @Optional("it-vpc-subnet") String vpcSubnet) {
    ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(defaultAccesKey, defaultTenantId, defaultSecretKey, null);
    Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(defaultSubscriptionId);
    azure.networks().define(vpcName).withRegion(regionName).withNewResourceGroup(resourceGroupName).withAddressSpace("10.0.0.0/16").withSubnet(vpcSubnet, "10.0.0.0/16").create();
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    Map<String, Object> map = new HashMap<>();
    map.put("networkId", vpcName);
    map.put("subnetId", vpcSubnet);
    map.put("resourceGroupName", resourceGroupName);
    networkRequest.setParameters(map);
    networkRequest.setCloudPlatform("AZURE");
    // networkJson.setPublicInAccount(publicInAccount);
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : Azure(com.microsoft.azure.management.Azure) HashMap(java.util.HashMap) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) 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