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;
}
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;
}
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;
}
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;
}
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++;
}
}
Aggregations