Search in sources :

Example 1 with AwsEfsFileSystem

use of com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method setupEfsFileSystemValidSet.

private AwsEfsFileSystem setupEfsFileSystemValidSet() {
    String fileSystemName = "efs-test";
    Map<String, String> fileSystemTags = new HashMap<>();
    fileSystemTags.put(CloudEfsConfiguration.KEY_FILESYSTEM_TAGS_NAME, fileSystemName);
    JSONObject fileSystemPolicy = null;
    try {
        fileSystemPolicy = new JSONObject("{\"Version\": \"2012-10-17\",\"Statement\": [{\"Effect\": \"Allow\",\"Action\": " + "[\"elasticfilesystem:ClientMount\"],\"Principal\":  {\"AWS\": \"arn:aws:iam::111122223333:root\"}}]}");
    } catch (JSONException e) {
    }
    // It does not make sense to have more than one such policy. but to test the syntex, create two policies
    List<String> lifeCyclePolicies = new ArrayList<>();
    lifeCyclePolicies.add("{\"TransitionToIA\" : \"AFTER_30_DAYS\"}");
    lifeCyclePolicies.add("{\"TransitionToIA\" : \"AFTER_7_DAYS\"}");
    return new AwsEfsFileSystem("DISABLED", false, fileSystemPolicy != null ? fileSystemPolicy.toString() : null, fileSystemTags, "sdx-key", lifeCyclePolicies, "maxIO", 1.0, "provisioned");
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with AwsEfsFileSystem

use of com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem in project cloudbreak by hortonworks.

the class AwsModelService method buildDefaultModelContext.

public ModelContext buildDefaultModelContext(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier) {
    Network network = stack.getNetwork();
    AwsNetworkView awsNetworkView = new AwsNetworkView(network);
    AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
    String regionName = ac.getCloudContext().getLocation().getRegion().value();
    AmazonEc2Client amazonEC2Client = awsClient.createEc2Client(credentialView, regionName);
    boolean mapPublicIpOnLaunch = awsNetworkService.isMapPublicOnLaunch(awsNetworkView, amazonEC2Client);
    boolean existingVPC = awsNetworkView.isExistingVPC();
    boolean existingSubnet = awsNetworkView.isExistingSubnet();
    String cidr = network.getSubnet().getCidr();
    String subnet = isNoCIDRProvided(existingVPC, existingSubnet, cidr) ? awsNetworkService.findNonOverLappingCIDR(ac, stack) : cidr;
    AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
    ModelContext modelContext = new ModelContext().withAuthenticatedContext(ac).withStack(stack).withExistingVpc(existingVPC).withExistingIGW(awsNetworkView.isExistingIGW()).withExistingSubnetCidr(existingSubnet ? awsNetworkService.getExistingSubnetCidr(ac, stack) : null).withExistinVpcCidr(awsNetworkService.getVpcCidrs(ac, awsNetworkView)).withExistingSubnetIds(existingSubnet ? awsNetworkView.getSubnetList() : null).mapPublicIpOnLaunch(mapPublicIpOnLaunch).withEnableInstanceProfile(awsInstanceProfileView.isInstanceProfileAvailable()).withInstanceProfileAvailable(awsInstanceProfileView.isInstanceProfileAvailable()).withTemplate(stack.getTemplate()).withDefaultSubnet(subnet).withOutboundInternetTraffic(network.getOutboundInternetTraffic()).withVpcCidrs(network.getNetworkCidrs()).withPrefixListIds(awsNetworkService.getPrefixListIds(amazonEC2Client, regionName, network.getOutboundInternetTraffic()));
    AwsEfsFileSystem efsFileSystem = getAwsEfsFileSystem(stack);
    if (efsFileSystem != null) {
        modelContext.withEnableEfs(true);
        modelContext.withEfsFileSystem(efsFileSystem);
    } else {
        modelContext.withEnableEfs(false);
    }
    return modelContext;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) Network(com.sequenceiq.cloudbreak.cloud.model.Network) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceProfileView)

Example 3 with AwsEfsFileSystem

use of com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestEfsNullFields.

@Test
public void buildTestEfsNullFields() {
    // GIVEN
    AwsEfsFileSystem awsEfsFileSystem = setupEfsFileSystemNullFields();
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withEnableEfs(true).withEfsFileSystem(awsEfsFileSystem);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("AWS::EFS::FileSystem").contains("\"Encrypted\" : \"true\"").contains("\"PerformanceMode\": \"generalPurpose\"").contains("\"ThroughputMode\": \"bursting\"");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Example 4 with AwsEfsFileSystem

use of com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestEfsSetFields.

@Test
public void buildTestEfsSetFields() {
    // GIVEN
    AwsEfsFileSystem awsEfsFileSystem = setupEfsFileSystemValidSet();
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withEnableEfs(true).withEfsFileSystem(awsEfsFileSystem);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("AWS::EFS::FileSystem").contains("\"Encrypted\" : \"false\"").contains("\"PerformanceMode\": \"maxIO\"").contains("\"ThroughputMode\": \"provisioned\"");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Aggregations

AwsEfsFileSystem (com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem)4 ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)2 Test (org.junit.jupiter.api.Test)2 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 AwsInstanceProfileView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceProfileView)1 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1