Search in sources :

Example 1 with SecurityRuleRequest

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

the class SecurityGroupToSecurityGroupResponseConverterTest method testConvert.

@Test
public void testConvert() {
    // GIVEN
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new ArrayList<SecurityRuleRequest>());
    // WHEN
    SecurityGroupResponse result = underTest.convert(getSource());
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("owner", "account"));
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) SecurityGroupResponse(com.sequenceiq.cloudbreak.api.model.SecurityGroupResponse) SecurityRuleRequest(com.sequenceiq.cloudbreak.api.model.SecurityRuleRequest) Test(org.junit.Test)

Example 2 with SecurityRuleRequest

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

the class SecurityRuleToSecurityRuleRequestConverter method convert.

@Override
public SecurityRuleRequest convert(SecurityRule source) {
    SecurityRuleRequest securityRuleRequest = new SecurityRuleRequest();
    StringBuilder sb = new StringBuilder();
    for (String portDefinition : source.getPorts()) {
        sb.append(String.format("%s,", portDefinition));
    }
    securityRuleRequest.setPorts(sb.toString().substring(0, sb.toString().length() - 1));
    securityRuleRequest.setProtocol(source.getProtocol());
    securityRuleRequest.setSubnet(source.getCidr());
    return securityRuleRequest;
}
Also used : SecurityRuleRequest(com.sequenceiq.cloudbreak.api.model.SecurityRuleRequest)

Example 3 with SecurityRuleRequest

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

the class SecurityGroupCreationTest method testSecurityGroupCreation.

@Test
@Parameters({ "name", "ports", "provider" })
public void testSecurityGroupCreation(@Optional("it-restricted-ambari") String name, @Optional("22,443,9443,8080") String ports, @Optional("MOCK") String provider) {
    // GIVEN
    // WHEN
    SecurityGroupRequest securityGroupRequest = new SecurityGroupRequest();
    securityGroupRequest.setDescription("Security group created by IT");
    securityGroupRequest.setName(name);
    SecurityRuleRequest securityRuleRequest = new SecurityRuleRequest("");
    securityRuleRequest.setProtocol("tcp");
    securityRuleRequest.setSubnet("0.0.0.0/0");
    securityRuleRequest.setPorts(ports);
    securityGroupRequest.setSecurityRules(Collections.singletonList(securityRuleRequest));
    securityGroupRequest.setCloudPlatform(provider);
    String id = getCloudbreakClient().securityGroupEndpoint().postPrivate(securityGroupRequest).getId().toString();
    // THEN
    Assert.assertNotNull(id);
    getItContext().putContextParam(CloudbreakITContextConstants.SECURITY_GROUP_ID, id, true);
}
Also used : SecurityGroupRequest(com.sequenceiq.cloudbreak.api.model.SecurityGroupRequest) SecurityRuleRequest(com.sequenceiq.cloudbreak.api.model.SecurityRuleRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with SecurityRuleRequest

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

the class InstanceGroupV2PreparationTest method createSecurityRequest.

@BeforeMethod(dependsOnGroups = "igRequestCreation")
@Parameters({ "group", "securityRules" })
public void createSecurityRequest(String group, String securityRules) {
    IntegrationTestContext itContext = getItContext();
    Map<String, InstanceGroupV2Request> igMap = itContext.getContextParam(CloudbreakV2Constants.INSTANCEGROUP_MAP, Map.class);
    InstanceGroupV2Request instanceGroupV2Request = igMap.get(group);
    SecurityGroupV2Request securityGroupV2Request = new SecurityGroupV2Request();
    List<String[]> secRules = templateAdditionHelper.parseCommaSeparatedRows(securityRules);
    List<SecurityRuleRequest> secRulesRequests = Lists.newArrayList();
    for (String[] secRule : secRules) {
        SecurityRuleRequest securityRuleRequest = new SecurityRuleRequest();
        securityRuleRequest.setProtocol(secRule[0]);
        securityRuleRequest.setSubnet(secRule[1]);
        securityRuleRequest.setPorts(secRule[2]);
        secRulesRequests.add(securityRuleRequest);
    }
    securityGroupV2Request.setSecurityRules(secRulesRequests);
    instanceGroupV2Request.setSecurityGroup(securityGroupV2Request);
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) InstanceGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request) SecurityGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.SecurityGroupV2Request) SecurityRuleRequest(com.sequenceiq.cloudbreak.api.model.SecurityRuleRequest) Parameters(org.testng.annotations.Parameters) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with SecurityRuleRequest

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

the class CloudProviderHelper method rules.

List<SecurityRuleRequest> rules() {
    List<SecurityRuleRequest> rules = new ArrayList<>();
    SecurityRuleRequest a = new SecurityRuleRequest();
    a.setSubnet("0.0.0.0/0");
    a.setProtocol("tcp");
    a.setPorts("22,443,8443,9443,8080");
    rules.add(a);
    return rules;
}
Also used : ArrayList(java.util.ArrayList) SecurityRuleRequest(com.sequenceiq.cloudbreak.api.model.SecurityRuleRequest)

Aggregations

SecurityRuleRequest (com.sequenceiq.cloudbreak.api.model.SecurityRuleRequest)6 Parameters (org.testng.annotations.Parameters)2 SecurityGroupRequest (com.sequenceiq.cloudbreak.api.model.SecurityGroupRequest)1 SecurityGroupResponse (com.sequenceiq.cloudbreak.api.model.SecurityGroupResponse)1 InstanceGroupV2Request (com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request)1 SecurityGroupV2Request (com.sequenceiq.cloudbreak.api.model.v2.SecurityGroupV2Request)1 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1