Search in sources :

Example 1 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class InstanceMetadataServiceComponentTest method saveInstanceAndGetUpdatedStack.

@Test
public void saveInstanceAndGetUpdatedStack() {
    DetailedEnvironmentResponse detailedEnvResponse = DetailedEnvironmentResponse.builder().withCrn(ENV_CRN).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("sub1", cloudSubnet("az", "sub1"), "sub2", cloudSubnet("az", "sub2"), "sub3", cloudSubnet("az", "sub3"), "sub4", cloudSubnet("az1", "sub4"))).build()).build();
    Stack stack = new Stack();
    stack.setEnvironmentCrn(ENV_CRN);
    InstanceGroup workerInstanceGroup = new InstanceGroup();
    workerInstanceGroup.setGroupName("worker");
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    instanceGroupNetwork.setCloudPlatform("AWS");
    instanceGroupNetwork.setAttributes(new Json(Map.of(SUBNET_IDS, List.of("sub1", "sub2", "sub3", "sub4"))));
    workerInstanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    stack.setInstanceGroups(Set.of(workerInstanceGroup));
    when(cachedEnvironmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setHostname("hostname");
    freeIpa.setDomain("domain");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, cloudInstances(42));
    Map<String, List<InstanceMetaData>> groupBySub = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getSubnetId, Collectors.mapping(Function.identity(), Collectors.toList())));
    Map<String, List<InstanceMetaData>> groupByAz = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getAvailabilityZone, Collectors.mapping(Function.identity(), Collectors.toList())));
    Assertions.assertEquals(2, groupByAz.size());
    Assertions.assertEquals(21, groupByAz.get("az").size());
    Assertions.assertEquals(21, groupByAz.get("az1").size());
    Assertions.assertEquals(4, groupBySub.size());
    Assertions.assertEquals(7, groupBySub.get("sub1").size());
    Assertions.assertEquals(7, groupBySub.get("sub2").size());
    Assertions.assertEquals(7, groupBySub.get("sub3").size());
    Assertions.assertEquals(21, groupBySub.get("sub4").size());
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testGetPathWithStackWithServiceNameRegistered.

@Test
public void testGetPathWithStackWithServiceNameRegistered() {
    when(clusterProxyConfiguration.getClusterProxyBasePath()).thenReturn("basePath");
    Stack stack = getAStack();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    ReadConfigResponse readConfigResponse = new ReadConfigResponse();
    ReadConfigService service = new ReadConfigService();
    service.setName("registered");
    readConfigResponse.setServices(List.of(service));
    when(clusterProxyRegistrationClient.readConfig(STACK_RESOURCE_CRN)).thenReturn(readConfigResponse);
    String result = underTest.getProxyPath(stack, Optional.of("registered"));
    assertEquals("basePath/proxy/resourceCrn/registered", result);
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ReadConfigService(com.sequenceiq.cloudbreak.clusterproxy.ReadConfigService) ReadConfigResponse(com.sequenceiq.cloudbreak.clusterproxy.ReadConfigResponse) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testGetPathWithStackWithoutServiceName.

@Test
public void testGetPathWithStackWithoutServiceName() {
    when(clusterProxyConfiguration.getClusterProxyBasePath()).thenReturn("basePath");
    Stack stack = getAStack();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    String result = underTest.getProxyPath(stack, Optional.empty());
    assertEquals("basePath/proxy/resourceCrn/freeipa.ipadom", result);
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testClusterProxyRegistrationWhenCCMDisabled.

@Test
public void testClusterProxyRegistrationWhenCCMDisabled() {
    Stack aStack = getAStack();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    GatewayConfig gatewayConfig = new GatewayConfig("connectionAddress", "publicAddress", PRIVATE_ADDRESS, 9443, "instanceId", false);
    ConfigRegistrationResponse configRegResponse = mock(ConfigRegistrationResponse.class);
    when(stackService.getStackById(STACK_ID)).thenReturn(aStack);
    when(clusterProxyEnablementService.isClusterProxyApplicable(any())).thenReturn(true);
    when(gatewayConfigService.getPrimaryGatewayConfig(aStack)).thenReturn(gatewayConfig);
    when(securityConfigService.findOneByStack(aStack)).thenReturn(null);
    when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(configRegResponse);
    when(stackUpdater.updateClusterProxyRegisteredFlag(aStack, true)).thenReturn(aStack);
    when(freeIpaService.findByStack(aStack)).thenReturn(freeIpa);
    underTest.registerFreeIpaForBootstrap(STACK_ID);
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_RESOURCE_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertFalse(proxyRegistrationReq.isUseCcmV2(), "CCMV2 should not be enabled.");
    assertFalse(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should not be enabled");
    assertNull(proxyRegistrationReq.getCcmV2Configs(), "CCMV2 config should not be initialized");
    assertNull(proxyRegistrationReq.getTunnels(), "CCMV1 tunnel should not be initialized");
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://publicAddress:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.ipadom", List.of("https://publicAddress:9443"), List.of(), null));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testUpdateClusterProxyRegistrationWhenCCMV2OrJumpgate.

@ParameterizedTest
@EnumSource(value = Tunnel.class, names = { "CCMV2", "CCMV2_JUMPGATE" }, mode = EnumSource.Mode.INCLUDE)
public void testUpdateClusterProxyRegistrationWhenCCMV2OrJumpgate(Tunnel ccmv2Mode) {
    Stack aStack = getAStack();
    aStack.setTunnel(ccmv2Mode);
    aStack.setCcmV2AgentCrn("testAgentCrn");
    SecurityConfig securityConfig = new SecurityConfig();
    securityConfig.setUsePrivateIpToTls(true);
    aStack.setSecurityConfig(securityConfig);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("test.freeipa.domain");
    GatewayConfig primaryGateway = new GatewayConfig("primaryAddress", "primaryPublicAddress", "primaryPrivateAddress", ServiceFamilies.GATEWAY.getDefaultPort(), "privateInstanceId", true);
    GatewayConfig gatewayConfig1 = new GatewayConfig("connectionAddress1", "publicIpAddress1", PRIVATE_IP_ADDRESS_1, ServiceFamilies.GATEWAY.getDefaultPort(), "testInstanceId1", true);
    ReflectionTestUtils.setField(gatewayConfig1, "hostname", "hostname1");
    GatewayConfig gatewayConfig2 = new GatewayConfig("connectionAddress2", "publicIpAddress2", PRIVATE_IP_ADDRESS_2, ServiceFamilies.GATEWAY.getDefaultPort(), "testInstanceId2", true);
    ReflectionTestUtils.setField(gatewayConfig2, "hostname", "hostname2");
    ConfigRegistrationResponse configRegResponse = mock(ConfigRegistrationResponse.class);
    when(stackService.getStackById(STACK_ID)).thenReturn(aStack);
    when(clusterProxyEnablementService.isClusterProxyApplicable(any())).thenReturn(true);
    when(gatewayConfigService.getPrimaryGatewayConfig(aStack)).thenReturn(primaryGateway);
    when(gatewayConfigService.getNotDeletedGatewayConfigs(aStack)).thenReturn(List.of(gatewayConfig1, gatewayConfig2));
    when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(configRegResponse);
    when(freeIpaService.findByStack(aStack)).thenReturn(freeIpa);
    when(clusterProxyServiceAvailabilityChecker.isDnsBasedServiceNameAvailable(aStack)).thenReturn(true);
    when(serviceEndpointHealthPollingService.pollWithTimeout(any(), any(), anyLong(), anyInt(), anyInt())).thenReturn(null);
    when(stackUpdater.updateClusterProxyRegisteredFlag(aStack, true)).thenReturn(aStack);
    when(healthCheckAvailabilityChecker.isCdpFreeIpaHeathAgentAvailable(aStack)).thenReturn(true);
    ReflectionTestUtils.setField(underTest, "intervalInSecV2", INTERVAL_IN_SEC_V_2);
    ReflectionTestUtils.setField(underTest, "healthStatusEndpointV2", HEALTH_STATUS_ENDPOINT_V_2);
    ReflectionTestUtils.setField(underTest, "timeoutInSecV2", TIMEOUT_IN_SEC_V_2);
    ReflectionTestUtils.setField(underTest, "healthyStatusCodeV2", HEALTHY_STATUS_CODE_V_2);
    underTest.updateFreeIpaRegistrationAndWait(STACK_ID, List.of("testInstanceId1", "testInstanceId2"));
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_RESOURCE_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertFalse(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should not be enabled");
    assertTrue(proxyRegistrationReq.isUseCcmV2(), ccmv2Mode + " should be enabled.");
    assertEquals(List.of(new CcmV2Config("testAgentCrn", PRIVATE_IP_ADDRESS_1, ServiceFamilies.GATEWAY.getDefaultPort(), "testAgentCrn-testInstanceId1", FREEIPA_SERVICE), new CcmV2Config("testAgentCrn", PRIVATE_IP_ADDRESS_2, ServiceFamilies.GATEWAY.getDefaultPort(), "testAgentCrn-testInstanceId2", FREEIPA_SERVICE)), proxyRegistrationReq.getCcmV2Configs(), ccmv2Mode + " config should match");
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://primaryPrivateAddress:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).doesNotContain(new ClusterServiceConfig("freeipa.test.freeipa.domain", List.of("https://primaryPrivateAddress:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("hostname1", List.of("https://privateIpAddress1:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("hostname2", List.of("https://privateIpAddress2:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.test.freeipa.domain", List.of("https://privateIpAddress1:9443", "https://privateIpAddress2:9443"), null, false, List.of(), null, new ClusterServiceHealthCheck(INTERVAL_IN_SEC_V_2, HEALTH_STATUS_ENDPOINT_V_2, TIMEOUT_IN_SEC_V_2, HEALTHY_STATUS_CODE_V_2)));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) ClusterServiceHealthCheck(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceHealthCheck) ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) CcmV2Config(com.sequenceiq.cloudbreak.clusterproxy.CcmV2Config) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)75 Stack (com.sequenceiq.freeipa.entity.Stack)62 Test (org.junit.jupiter.api.Test)50 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)10 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)10 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)10 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)8 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)7 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)6 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)6 DnsRecord (com.sequenceiq.freeipa.client.model.DnsRecord)6 Set (java.util.Set)6 ClusterServiceConfig (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig)5 ConfigRegistrationRequest (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest)5 ConfigRegistrationResponse (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse)5 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)5 Optional (java.util.Optional)5