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.");
}
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)));
}
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)));
}
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.");
}
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)));
}
Aggregations