use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest in project cloudbreak by hortonworks.
the class ClusterProxyServiceTest method testRegisterClusterWhenCCMV1.
@Test
void testRegisterClusterWhenCCMV1() throws ClusterProxyException, JsonProcessingException {
Stack stack = testStackUsingCCM();
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);
assertFalse(proxyRegistrationReq.isUseCcmV2(), "CCMV2 should not be enabled.");
assertNull(proxyRegistrationReq.getCcmV2Configs(), "CCMV2 config should not be initialized.");
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 testClusterProxyRegistrationWhenCCMV2OrJumpgate.
@ParameterizedTest
@EnumSource(value = Tunnel.class, names = { "CCMV2", "CCMV2_JUMPGATE" }, mode = EnumSource.Mode.INCLUDE)
public void testClusterProxyRegistrationWhenCCMV2OrJumpgate(Tunnel ccmv2Mode) {
Stack aStack = getAStack();
aStack.setTunnel(ccmv2Mode);
aStack.setCcmV2AgentCrn("testAgentCrn");
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain("ipadom");
GatewayConfig gatewayConfig = new GatewayConfig("connectionAddress", "publicIpAddress", PRIVATE_IP_ADDRESS, ServiceFamilies.GATEWAY.getDefaultPort(), "testInstanceId", true);
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.isUseTunnel(), "CCMV1 tunnel should not be enabled");
assertTrue(proxyRegistrationReq.isUseCcmV2(), ccmv2Mode + " should be enabled.");
assertEquals(List.of(new CcmV2Config("testAgentCrn", PRIVATE_IP_ADDRESS, ServiceFamilies.GATEWAY.getDefaultPort(), "testAgentCrn-testInstanceId", FREEIPA_SERVICE)), proxyRegistrationReq.getCcmV2Configs(), ccmv2Mode + " config should match");
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://privateIpAddress:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.ipadom", List.of("https://privateIpAddress:9443"), List.of(), null));
}
use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest in project cloudbreak by hortonworks.
the class ClusterProxyServiceTest method testClusterProxyRegistrationWhenCCMV1.
@Test
public void testClusterProxyRegistrationWhenCCMV1() {
Stack aStack = getAStack();
aStack.setTunnel(Tunnel.CCM);
aStack.setMinaSshdServiceId("minaSshdServiceId");
GatewayConfig gatewayConfig = new GatewayConfig("connectionAddress", "publicAddress", PRIVATE_ADDRESS, 9443, "instanceId", false);
ConfigRegistrationResponse configRegResponse = mock(ConfigRegistrationResponse.class);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain("ipadom");
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.");
assertTrue(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should be enabled");
assertEquals(List.of(new TunnelEntry("instanceId", "GATEWAY", PRIVATE_ADDRESS, 9443, "minaSshdServiceId")), proxyRegistrationReq.getTunnels(), "CCMV1 tunnel should be configured.");
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://privateAddress:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.ipadom", List.of("https://privateAddress:9443"), List.of(), null));
}
use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest in project cloudbreak by hortonworks.
the class ClusterProxyService method registerFreeIpa.
private Optional<ConfigRegistrationResponse> registerFreeIpa(Stack stack, List<String> instanceIdsToRegister, boolean bootstrap, boolean waitForGoodHealth) {
MDCBuilder.buildMdcContext(stack);
if (!clusterProxyEnablementService.isClusterProxyApplicable(stack.getCloudPlatform())) {
LOGGER.debug("Cluster Proxy integration disabled. Skipping registering FreeIpa [{}]", stack);
return Optional.empty();
}
LOGGER.debug("Registering freeipa with cluster-proxy: Environment CRN = [{}], Stack CRN = [{}], bootstrap: [{}], waitForGoodHealth: [{}]", stack.getEnvironmentCrn(), stack.getResourceCrn(), bootstrap, waitForGoodHealth);
GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
List<GatewayConfig> gatewayConfigs = gatewayConfigService.getNotDeletedGatewayConfigs(stack);
ClientCertificate clientCertificate = clientCertificates(stack);
boolean preferPrivateIp = stack.getTunnel().useCcm();
List<GatewayConfig> tunnelGatewayConfigs;
List<ClusterServiceConfig> serviceConfigs = new LinkedList<>();
serviceConfigs.add(createServiceConfig(stack, FREEIPA_SERVICE_NAME, primaryGatewayConfig, clientCertificate, preferPrivateIp));
if (bootstrap) {
tunnelGatewayConfigs = List.of(primaryGatewayConfig);
serviceConfigs.add(createServiceConfig(stack, generateFreeIpaFqdn(stack), primaryGatewayConfig, clientCertificate, preferPrivateIp));
} else if (clusterProxyServiceAvailabilityChecker.isDnsBasedServiceNameAvailable(stack)) {
List<GatewayConfig> targetGatewayConfigs = gatewayConfigs.stream().filter(gatewayConfig -> Objects.nonNull(gatewayConfig.getInstanceId())).filter(gatewayConfig -> Objects.isNull(instanceIdsToRegister) || instanceIdsToRegister.contains(gatewayConfig.getInstanceId())).collect(Collectors.toList());
serviceConfigs.addAll(createDnsMappedServiceConfigs(stack, targetGatewayConfigs, clientCertificate, preferPrivateIp));
tunnelGatewayConfigs = targetGatewayConfigs;
} else {
tunnelGatewayConfigs = List.of(primaryGatewayConfig);
}
ConfigRegistrationRequestBuilder requestBuilder = new ConfigRegistrationRequestBuilder(stack.getResourceCrn()).withServices(serviceConfigs).withAccountId(stack.getAccountId());
if (stack.getTunnel().useCcmV1()) {
requestBuilder.withTunnelEntries(createTunnelEntries(stack, tunnelGatewayConfigs));
} else if (stack.getTunnel().useCcmV2OrJumpgate()) {
requestBuilder.withCcmV2Entries(createCcmV2Configs(stack, tunnelGatewayConfigs));
}
ConfigRegistrationRequest request = requestBuilder.build();
LOGGER.debug("Registering cluster proxy configuration [{}]", request);
ConfigRegistrationResponse response = clusterProxyRegistrationClient.registerConfig(request);
if (waitForGoodHealth) {
pollForGoodHealth(stack);
}
stackUpdater.updateClusterProxyRegisteredFlag(stack, true);
return Optional.of(response);
}
Aggregations