use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig in project cloudbreak by hortonworks.
the class ClusterProxyServiceTest method cmInternalServiceConfig.
private ClusterServiceConfig cmInternalServiceConfig(boolean withPrivateIp) {
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", List.of(withPrivateIp ? "https://10.10.10.10:9443" : "https://1.2.3.4:9443"), null, false, asList(cloudbreakUser, dpUser), clientCertificate, null);
}
use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig in project cloudbreak by hortonworks.
the class ClusterProxyService method cmServiceConfig.
private ClusterServiceConfig cmServiceConfig(Stack stack, ClientCertificate clientCertificate, String serviceName, String clusterManagerUrl) {
Cluster cluster = stack.getCluster();
String cloudbreakUser = cluster.getCloudbreakAmbariUser();
String cloudbreakPasswordVaultPath = vaultPath(cluster.getCloudbreakAmbariPasswordSecret(), false);
String dpUser = cluster.getDpAmbariUser();
String dpPasswordVaultPath = vaultPath(cluster.getDpAmbariPasswordSecret(), false);
List<ClusterServiceCredential> credentials = asList(new ClusterServiceCredential(cloudbreakUser, cloudbreakPasswordVaultPath), new ClusterServiceCredential(dpUser, dpPasswordVaultPath, true));
return new ClusterServiceConfig(serviceName, singletonList(clusterManagerUrl), credentials, clientCertificate);
}
use of com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig 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.ClusterServiceConfig 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.ClusterServiceConfig 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