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