Search in sources :

Example 1 with ClusterServiceConfig

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig 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 2 with ClusterServiceConfig

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig 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)

Example 3 with ClusterServiceConfig

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method cmServiceConfigWithInstanceId.

private ClusterServiceConfig cmServiceConfigWithInstanceId(String ipAddress, String instanceId) {
    ClusterServiceCredential cloudbreakUser = new ClusterServiceCredential("cloudbreak", "/cb/test-data/secret/cbpassword:secret");
    ClusterServiceCredential dpUser = new ClusterServiceCredential("cmmgmt", "/cb/test-data/secret/dppassword:secret", true);
    ClientCertificate clientCertificate = new ClientCertificate("/cb/test-data/secret/clientKey:secret:base64", "/cb/test-data/secret/clientCert:secret:base64");
    return new ClusterServiceConfig("cb-internal-" + instanceId, List.of("https://" + ipAddress + ":9443"), null, false, asList(cloudbreakUser, dpUser), clientCertificate, null);
}
Also used : ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) ClusterServiceCredential(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceCredential) ClientCertificate(com.sequenceiq.cloudbreak.clusterproxy.ClientCertificate)

Example 4 with ClusterServiceConfig

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method cmServiceConfig.

private ClusterServiceConfig cmServiceConfig() {
    ClusterServiceCredential cloudbreakUser = new ClusterServiceCredential("cloudbreak", "/cb/test-data/secret/cbpassword:secret");
    ClusterServiceCredential dpUser = new ClusterServiceCredential("cmmgmt", "/cb/test-data/secret/dppassword:secret", true);
    ClientCertificate clientCertificate = new ClientCertificate("/cb/test-data/secret/clientKey:secret:base64", "/cb/test-data/secret/clientCert:secret:base64");
    return new ClusterServiceConfig(CLOUDERA_MANAGER_SERVICE, List.of("https://10.10.10.10:9443"), null, false, asList(cloudbreakUser, dpUser), clientCertificate, null);
}
Also used : ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) ClusterServiceCredential(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceCredential) ClientCertificate(com.sequenceiq.cloudbreak.clusterproxy.ClientCertificate)

Example 5 with ClusterServiceConfig

use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig in project cloudbreak by hortonworks.

the class ClusterProxyService method createDnsMappedServiceConfigs.

private List<ClusterServiceConfig> createDnsMappedServiceConfigs(Stack stack, List<GatewayConfig> gatewayConfigs, ClientCertificate clientCertificate, boolean preferPrivateIp) {
    List<ClusterServiceConfig> serviceConfigs = gatewayConfigs.stream().map(gatewayConfig -> createServiceConfig(stack, gatewayConfig.getHostname(), gatewayConfig, clientCertificate, preferPrivateIp)).collect(Collectors.toList());
    List<String> endpoints = gatewayConfigs.stream().map(gatewayConfig -> getNginxEndpointForRegistration(stack, gatewayConfig, preferPrivateIp)).collect(Collectors.toList());
    serviceConfigs.add(new ClusterServiceConfig(generateFreeIpaFqdn(stack), endpoints, null, false, List.of(), clientCertificate, getHealthCheck(stack)));
    return serviceConfigs;
}
Also used : FreeIpaCertVaultComponent(com.sequenceiq.freeipa.vault.FreeIpaCertVaultComponent) CCMV2_BACKEND_ID_FORMAT(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2ParameterConstants.CCMV2_BACKEND_ID_FORMAT) FreeIpaDomainUtils(com.sequenceiq.freeipa.service.config.FreeIpaDomainUtils) LoggerFactory(org.slf4j.LoggerFactory) ConfigRegistrationRequestBuilder(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequestBuilder) ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) StringUtils(org.apache.commons.lang3.StringUtils) ClusterProxyConfiguration(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyConfiguration) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) VaultSecret(com.sequenceiq.cloudbreak.service.secret.vault.VaultSecret) TunnelEntry(com.sequenceiq.cloudbreak.clusterproxy.TunnelEntry) Service(org.springframework.stereotype.Service) LinkedList(java.util.LinkedList) ServiceFamilies(com.sequenceiq.cloudbreak.ccm.endpoint.ServiceFamilies) Tunnel(com.sequenceiq.common.api.type.Tunnel) Stack(com.sequenceiq.freeipa.entity.Stack) VaultConfigException(com.sequenceiq.cloudbreak.service.secret.vault.VaultConfigException) ClientCertificate(com.sequenceiq.cloudbreak.clusterproxy.ClientCertificate) ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) Logger(org.slf4j.Logger) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ClusterServiceHealthCheck(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceHealthCheck) ReadConfigResponse(com.sequenceiq.cloudbreak.clusterproxy.ReadConfigResponse) IOException(java.io.IOException) ServiceEndpointHealthListenerTask(com.sequenceiq.freeipa.service.polling.clusterproxy.ServiceEndpointHealthListenerTask) SecurityConfigService(com.sequenceiq.freeipa.service.SecurityConfigService) ClusterProxyServiceAvailabilityChecker(com.sequenceiq.freeipa.util.ClusterProxyServiceAvailabilityChecker) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ServiceEndpointHealthPollerObject(com.sequenceiq.freeipa.service.polling.clusterproxy.ServiceEndpointHealthPollerObject) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) List(java.util.List) ClusterProxyRegistrationClient(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyRegistrationClient) GatewayConfigService(com.sequenceiq.freeipa.service.GatewayConfigService) PollingService(com.sequenceiq.cloudbreak.polling.PollingService) FreeIpaService(com.sequenceiq.freeipa.service.freeipa.FreeIpaService) CcmV2Config(com.sequenceiq.cloudbreak.clusterproxy.CcmV2Config) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) HealthCheckAvailabilityChecker(com.sequenceiq.freeipa.util.HealthCheckAvailabilityChecker) ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig)

Aggregations

ClusterServiceConfig (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig)10 ConfigRegistrationRequest (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest)6 ConfigRegistrationResponse (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse)6 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)6 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 ClientCertificate (com.sequenceiq.cloudbreak.clusterproxy.ClientCertificate)5 CcmV2Config (com.sequenceiq.cloudbreak.clusterproxy.CcmV2Config)4 ClusterServiceCredential (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceCredential)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ClusterServiceHealthCheck (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceHealthCheck)3 TunnelEntry (com.sequenceiq.cloudbreak.clusterproxy.TunnelEntry)3 SecurityConfig (com.sequenceiq.freeipa.entity.SecurityConfig)3 CCMV2_BACKEND_ID_FORMAT (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2ParameterConstants.CCMV2_BACKEND_ID_FORMAT)2 ServiceFamilies (com.sequenceiq.cloudbreak.ccm.endpoint.ServiceFamilies)2 ClusterProxyConfiguration (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyConfiguration)2 ClusterProxyEnablementService (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService)2 ClusterProxyRegistrationClient (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyRegistrationClient)2 ConfigRegistrationRequestBuilder (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequestBuilder)2 ReadConfigResponse (com.sequenceiq.cloudbreak.clusterproxy.ReadConfigResponse)2