Search in sources :

Example 1 with SecurityGroupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest in project cloudbreak by hortonworks.

the class FreeIpaTestDto method mapSecurityGroupRequest.

private SecurityGroupRequest mapSecurityGroupRequest(InstanceGroupV4Request request) {
    SecurityGroupRequest securityGroup = new SecurityGroupRequest();
    securityGroup.setSecurityRules(request.getSecurityGroup().getSecurityRules().stream().map(sgreq -> {
        SecurityRuleRequest rule = new SecurityRuleRequest();
        rule.setModifiable(sgreq.isModifiable());
        rule.setPorts(sgreq.getPorts());
        rule.setProtocol(sgreq.getProtocol());
        rule.setSubnet(sgreq.getSubnet());
        return rule;
    }).collect(Collectors.toList()));
    securityGroup.setSecurityGroupIds(request.getSecurityGroup().getSecurityGroupIds());
    return securityGroup;
}
Also used : SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) SecurityRuleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityRuleRequest)

Example 2 with SecurityGroupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method createFreeIpaRequest.

private CreateFreeIpaRequest createFreeIpaRequest(EnvironmentDto environment) {
    boolean multiAzRequired = environment.getFreeIpaCreation().isEnableMultiAz();
    CreateFreeIpaRequest createFreeIpaRequest = new CreateFreeIpaRequest();
    createFreeIpaRequest.setEnvironmentCrn(environment.getResourceCrn());
    createFreeIpaRequest.setName(environment.getName() + "-freeipa");
    FreeIpaServerRequest freeIpaServerRequest = freeIpaServerRequestProvider.create(environment);
    createFreeIpaRequest.setFreeIpa(freeIpaServerRequest);
    setPlacementAndNetwork(environment, createFreeIpaRequest, multiAzRequired);
    setAuthentication(environment.getAuthentication(), createFreeIpaRequest);
    setTelemetry(environment, createFreeIpaRequest);
    setBackup(environment, createFreeIpaRequest);
    setTags(environment, createFreeIpaRequest);
    setImage(environment, createFreeIpaRequest);
    SecurityGroupRequest securityGroupRequest = null;
    if (environment.getSecurityAccess() != null) {
        securityGroupRequest = createSecurityGroupRequest(environment.getSecurityAccess());
    }
    createFreeIpaRequest.setInstanceGroups(createInstanceGroupRequests(createFreeIpaRequest, securityGroupRequest, environment, multiAzRequired));
    setVariant(environment, createFreeIpaRequest, multiAzRequired);
    setUseCcm(environment.getExperimentalFeatures().getTunnel(), createFreeIpaRequest);
    return createFreeIpaRequest;
}
Also used : CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)

Example 3 with SecurityGroupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method createInstanceGroupRequests.

private List<InstanceGroupRequest> createInstanceGroupRequests(CreateFreeIpaRequest createFreeIpaRequest, SecurityGroupRequest securityGroupRequest, EnvironmentDto environment, boolean multiAzRequired) {
    List<InstanceGroupRequest> instanceGroupRequests = new LinkedList<>();
    FreeIpaCreationDto freeIpaCreation = environment.getFreeIpaCreation();
    InstanceGroupRequest instanceGroupRequest = new InstanceGroupRequest();
    instanceGroupRequest.setName(MASTER_GROUP_NAME);
    instanceGroupRequest.setNodeCount(freeIpaCreation.getInstanceCountByGroup());
    instanceGroupRequest.setType(InstanceGroupType.MASTER);
    instanceGroupRequest.setSecurityGroup(securityGroupRequest);
    instanceGroupRequest.setInstanceTemplateRequest(createInstanceTemplate(freeIpaCreation));
    if (multiAzRequired && multiAzValidator.suportedMultiAzForEnvironment(environment.getCloudPlatform())) {
        FreeIpaNetworkProvider freeIpaNetworkProvider = freeIpaNetworkProviderMapByCloudPlatform.get(CloudPlatform.valueOf(environment.getCloudPlatform()));
        if (freeIpaNetworkProvider != null) {
            InstanceGroupNetworkRequest instanceGroupNetworkRequest = freeIpaNetworkProvider.networkByGroup(environment);
            instanceGroupRequest.setNetwork(instanceGroupNetworkRequest);
            createFreeIpaRequest.getPlacement().setAvailabilityZone(freeIpaNetworkProvider.availabilityZone(instanceGroupNetworkRequest, environment));
        }
    }
    instanceGroupRequests.add(instanceGroupRequest);
    return instanceGroupRequests;
}
Also used : InstanceGroupNetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest) InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) LinkedList(java.util.LinkedList)

Example 4 with SecurityGroupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method createSecurityGroupRequest.

private SecurityGroupRequest createSecurityGroupRequest(SecurityAccessDto securityAccess) {
    SecurityGroupRequest securityGroupRequest = new SecurityGroupRequest();
    if (!Strings.isNullOrEmpty(securityAccess.getCidr())) {
        securityGroupRequest.setSecurityRules(new ArrayList<>());
        for (String cidr : CidrUtil.cidrs(securityAccess.getCidr())) {
            SecurityRuleRequest securityRuleRequest = createSecurityRuleRequest(cidr);
            securityGroupRequest.getSecurityRules().add(securityRuleRequest);
        }
        securityGroupRequest.setSecurityGroupIds(new HashSet<>());
    } else if (!Strings.isNullOrEmpty(securityAccess.getDefaultSecurityGroupId())) {
        securityGroupRequest.setSecurityGroupIds(getSecurityGroupIds(securityAccess.getDefaultSecurityGroupId()));
        securityGroupRequest.setSecurityRules(new ArrayList<>());
    } else {
        securityGroupRequest.setSecurityRules(new ArrayList<>());
        securityGroupRequest.setSecurityGroupIds(new HashSet<>());
    }
    return securityGroupRequest;
}
Also used : SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) ArrayList(java.util.ArrayList) SecurityRuleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityRuleRequest) HashSet(java.util.HashSet)

Example 5 with SecurityGroupRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest in project cloudbreak by hortonworks.

the class InstanceGroupRequestToInstanceGroupConverterTest method testConvertWithNullTemplate.

@Test
public void testConvertWithNullTemplate() {
    int nodeCount = 2;
    InstanceGroupRequest request = new InstanceGroupRequest();
    request.setName(NAME);
    request.setType(InstanceGroupType.MASTER);
    request.setNodeCount(nodeCount);
    Template template = mock(Template.class);
    SecurityGroupRequest securityGroupRequest = mock(SecurityGroupRequest.class);
    SecurityGroup securityGroup = mock(SecurityGroup.class);
    request.setSecurityGroup(securityGroupRequest);
    Stack stack = new Stack();
    stack.setAccountId(ACCOUNT_ID);
    stack.setCloudPlatform(MOCK.name());
    stack.setName(NAME);
    FreeIpaServerRequest freeIpaServerRequest = new FreeIpaServerRequest();
    freeIpaServerRequest.setHostname(HOSTNAME);
    freeIpaServerRequest.setDomain(DOMAINNAME);
    NetworkRequest networkRequest = new NetworkRequest();
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    // GIVEN
    given(defaultInstanceGroupProvider.createDefaultTemplate(eq(MOCK), eq(ACCOUNT_ID), eq(null), eq(null), eq(null))).willReturn(template);
    given(securityGroupConverter.convert(eq(securityGroupRequest))).willReturn(securityGroup);
    // WHEN
    InstanceGroup result = underTest.convert(request, networkRequest, ACCOUNT_ID, stack, freeIpaServerRequest, detailedEnvironmentResponse, createAndGetCloudArgsForIgCoverterMap(null, null, null));
    // THEN
    assertThat(result).isNotNull();
    assertThat(result.getGroupName()).isEqualTo(NAME);
    assertThat(result.getInstanceGroupType()).isEqualTo(InstanceGroupType.MASTER);
    assertThat(result.getSecurityGroup()).isEqualTo(securityGroup);
    assertThat(result.getNodeCount()).isEqualTo(nodeCount);
    assertThat(result.getInstanceMetaData().size()).isEqualTo(nodeCount);
    int i = 0;
    for (InstanceMetaData instanceMetaData : result.getInstanceMetaData()) {
        assertThat(instanceMetaData.getInstanceGroup()).isEqualTo(result);
        assertThat(instanceMetaData.getDiscoveryFQDN()).startsWith(HOSTNAME + i);
        i++;
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) SecurityGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SecurityGroup(com.sequenceiq.freeipa.entity.SecurityGroup) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest) Template(com.sequenceiq.freeipa.entity.Template) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityGroupRequest)8 SecurityGroup (com.sequenceiq.freeipa.entity.SecurityGroup)4 SecurityRuleRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.security.SecurityRuleRequest)3 Test (org.junit.Test)3 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)2 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)2 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)1 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 FreeIpaCreationDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationDto)1 InstanceGroupNetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest)1 NetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)1 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)1 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 SecurityRule (com.sequenceiq.freeipa.entity.SecurityRule)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 Template (com.sequenceiq.freeipa.entity.Template)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1