Search in sources :

Example 6 with ConfigRegistrationRequest

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

the class ClusterProxyServiceTest method testRegisterClusterWhenCCMV2Jumpgate.

@Test
void testRegisterClusterWhenCCMV2Jumpgate() throws ClusterProxyException, JsonProcessingException {
    Stack stack = testStack();
    stack.setTunnel(Tunnel.CCMV2_JUMPGATE);
    stack.setCcmV2AgentCrn("testAgentCrn");
    when(securityConfigService.findOneByStackId(STACK_ID)).thenReturn(Optional.of(gatewaySecurityConfig()));
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    underTest.registerCluster(stack);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertTrue(proxyRegistrationReq.isUseCcmV2(), "CCMV2 should be enabled");
    assertNull(proxyRegistrationReq.getCcmV2Configs(), "CCMV2 config should be empty for Jumpgate");
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(PRIMARY_PRIVATE_IP, PRIMARY_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(OTHER_PRIVATE_IP, OTHER_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmInternalServiceConfig(true)));
    assertFalse(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should be disabled.");
    assertNull(proxyRegistrationReq.getTunnels(), "CCMV1 tunnel should not be configured.");
}
Also used : ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ConfigRegistrationRequest

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

the class ClusterProxyServiceTest method shouldRegisterProxyConfigurationWithClusterProxy.

@Test
void shouldRegisterProxyConfigurationWithClusterProxy() throws ClusterProxyException, JsonProcessingException {
    ConfigRegistrationResponse response = new ConfigRegistrationResponse();
    response.setX509Unwrapped("X509PublicKey");
    when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(response);
    when(securityConfigService.findOneByStackId(STACK_ID)).thenReturn(Optional.of(gatewaySecurityConfig()));
    Stack stack = testStackUsingCCM();
    ConfigRegistrationResponse registrationResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.registerCluster(stack));
    assertEquals("X509PublicKey", registrationResponse.getX509Unwrapped());
    ArgumentCaptor<ConfigRegistrationRequest> configRegistrationRequestArgumentCaptor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    verify(clusterProxyRegistrationClient).registerConfig(configRegistrationRequestArgumentCaptor.capture());
    ConfigRegistrationRequest requestSent = configRegistrationRequestArgumentCaptor.getValue();
    assertThat(requestSent.getClusterCrn()).isEqualTo(STACK_CRN);
    assertThat(requestSent.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertEquals(4, requestSent.getServices().size());
    assertTrue(requestSent.getServices().contains(cmServiceConfigWithInstanceId(PRIMARY_PRIVATE_IP, PRIMARY_INSTANCE_ID)));
    assertTrue(requestSent.getServices().contains(cmServiceConfigWithInstanceId(OTHER_PRIVATE_IP, OTHER_INSTANCE_ID)));
    assertTrue(requestSent.getServices().contains(cmServiceConfig()));
    assertTrue(requestSent.getServices().contains(cmInternalServiceConfig(true)));
}
Also used : ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ConfigRegistrationRequest

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

the class ClusterProxyServiceTest method testReRegisterClusterWhenCCMV1.

@Test
void testReRegisterClusterWhenCCMV1() throws ClusterProxyException, JsonProcessingException {
    Stack stack = testStackUsingCCM();
    Gateway gateway = new Gateway();
    gateway.setPath("test-cluster");
    stack.getCluster().setGateway(gateway);
    when(securityConfigService.findOneByStackId(STACK_ID)).thenReturn(Optional.of(gatewaySecurityConfig()));
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    underTest.reRegisterCluster(stack);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertFalse(proxyRegistrationReq.isUseCcmV2(), "CCMV2 should not be enabled.");
    assertNull(proxyRegistrationReq.getCcmV2Configs(), "CCMV2 config should not be initialized.");
    assertEquals("https://10.10.10.10/test-cluster", proxyRegistrationReq.getUriOfKnox(), "CCMV1 Knox URI should match");
    assertTrue(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should be enabled");
    assertThat(proxyRegistrationReq.getTunnels()).withFailMessage("CCMV1 tunnel should be configured.").hasSameElementsAs(tunnelEntries());
    assertEquals(4, proxyRegistrationReq.getServices().size());
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(PRIMARY_PRIVATE_IP, PRIMARY_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(OTHER_PRIVATE_IP, OTHER_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfig()));
    assertTrue(proxyRegistrationReq.getServices().contains(cmInternalServiceConfig(true)));
}
Also used : Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with ConfigRegistrationRequest

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

the class ClusterProxyServiceTest method testReRegisterClusterWhenCCMV2Jumpgate.

@Test
void testReRegisterClusterWhenCCMV2Jumpgate() throws ClusterProxyException, JsonProcessingException {
    Stack stack = testStack();
    stack.setTunnel(Tunnel.CCMV2_JUMPGATE);
    stack.setCcmV2AgentCrn("testAgentCrn");
    Gateway gateway = new Gateway();
    gateway.setPath("test-cluster");
    stack.getCluster().setId(1L);
    stack.getCluster().setGateway(gateway);
    when(securityConfigService.findOneByStackId(STACK_ID)).thenReturn(Optional.of(gatewaySecurityConfig()));
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    underTest.reRegisterCluster(stack);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertTrue(proxyRegistrationReq.isUseCcmV2(), "CCMV2 should be enabled");
    assertNull(proxyRegistrationReq.getCcmV2Configs(), "CCMV2 config should be empty for Jumpgate");
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(PRIMARY_PRIVATE_IP, PRIMARY_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(OTHER_PRIVATE_IP, OTHER_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmInternalServiceConfig(true)));
    assertEquals("https://10.10.10.10:9443/knox/test-cluster", proxyRegistrationReq.getUriOfKnox(), "CCMV2 Knox URI should match");
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(PRIMARY_PRIVATE_IP, PRIMARY_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmServiceConfigWithInstanceId(OTHER_PRIVATE_IP, OTHER_INSTANCE_ID)));
    assertTrue(proxyRegistrationReq.getServices().contains(cmInternalServiceConfig(true)));
    assertFalse(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should be disabled.");
    assertNull(proxyRegistrationReq.getTunnels(), "CCMV1 tunnel should not be configured.");
}
Also used : Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with ConfigRegistrationRequest

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

the class ClusterProxyServiceTest method shouldNotRegisterSSHTunnelInfoIfCCMIsDisabled.

@Test
void shouldNotRegisterSSHTunnelInfoIfCCMIsDisabled() throws ClusterProxyException, JsonProcessingException {
    ConfigRegistrationResponse response = new ConfigRegistrationResponse();
    response.setX509Unwrapped("X509PublicKey");
    when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(response);
    when(securityConfigService.findOneByStackId(STACK_ID)).thenReturn(Optional.of(gatewaySecurityConfig()));
    ConfigRegistrationResponse registrationResponse = underTest.registerCluster(testStack());
    assertEquals("X509PublicKey", registrationResponse.getX509Unwrapped());
    ArgumentCaptor<ConfigRegistrationRequest> configRegistrationRequestArgumentCaptor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    verify(clusterProxyRegistrationClient).registerConfig(configRegistrationRequestArgumentCaptor.capture());
    ConfigRegistrationRequest requestSent = configRegistrationRequestArgumentCaptor.getValue();
    assertThat(requestSent.getClusterCrn()).isEqualTo(STACK_CRN);
    assertThat(requestSent.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertEquals(4, requestSent.getServices().size());
    assertTrue(requestSent.getServices().contains(cmServiceConfigWithInstanceId(PRIMARY_PUBLIC_IP, PRIMARY_INSTANCE_ID)));
    assertTrue(requestSent.getServices().contains(cmServiceConfigWithInstanceId(OTHER_PUBLIC_IP, OTHER_INSTANCE_ID)));
    assertTrue(requestSent.getServices().contains(cmInternalServiceConfig(false)));
}
Also used : ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ConfigRegistrationRequest (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Test (org.junit.jupiter.api.Test)10 ConfigRegistrationResponse (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse)8 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 CcmV2Config (com.sequenceiq.cloudbreak.clusterproxy.CcmV2Config)5 ClusterServiceConfig (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig)5 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)5 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)5 Stack (com.sequenceiq.freeipa.entity.Stack)5 Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)3 ClusterServiceHealthCheck (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceHealthCheck)2 TunnelEntry (com.sequenceiq.cloudbreak.clusterproxy.TunnelEntry)2 SecurityConfig (com.sequenceiq.freeipa.entity.SecurityConfig)2 CCMV2_BACKEND_ID_FORMAT (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2ParameterConstants.CCMV2_BACKEND_ID_FORMAT)1 ServiceFamilies (com.sequenceiq.cloudbreak.ccm.endpoint.ServiceFamilies)1 ClientCertificate (com.sequenceiq.cloudbreak.clusterproxy.ClientCertificate)1 ClusterProxyConfiguration (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyConfiguration)1 ClusterProxyEnablementService (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService)1 ClusterProxyRegistrationClient (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyRegistrationClient)1