use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse in project cloudbreak by hortonworks.
the class ClusterProxyService method registerCluster.
public ConfigRegistrationResponse registerCluster(Stack stack) {
ConfigRegistrationRequest proxyConfigRequest = createProxyConfigRequest(stack);
ConfigRegistrationResponse configRegistrationResponse = clusterProxyRegistrationClient.registerConfig(proxyConfigRequest);
stackUpdater.updateClusterProxyRegisteredFlag(stack, true);
return configRegistrationResponse;
}
use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse in project cloudbreak by hortonworks.
the class ClusterProxyRegistrationHandler method registerCluster.
private Selectable registerCluster(ClusterProxyRegistrationRequest request) {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
try {
if (!clusterProxyEnablementService.isClusterProxyApplicable(request.getCloudPlatform())) {
LOGGER.info("Cluster Proxy integration is DISABLED, skipping registering with Cluster Proxy service. Cluster CRN: {}", stack.getResourceCrn());
return new ClusterProxyRegistrationSuccess(request.getResourceId());
}
ConfigRegistrationResponse registerResponse = clusterProxyService.registerCluster(stack);
Cluster cluster = stack.getCluster();
if (cluster.hasGateway()) {
LOGGER.debug("Updating Gateway for cluster {} in environment {} with public key certificate retrieved from Cluster Proxy", cluster.getId(), stack.getEnvironmentCrn());
Gateway gateway = cluster.getGateway();
gateway.setTokenCert(registerResponse.getX509Unwrapped());
gatewayService.save(gateway);
}
return new ClusterProxyRegistrationSuccess(request.getResourceId());
} catch (Exception e) {
LOGGER.error("Error occurred when registering cluster {} in environment {} to cluster proxy", stack.getCluster().getId(), stack.getEnvironmentCrn(), e);
return new ClusterProxyRegistrationFailed(request.getResourceId(), e);
}
}
use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse in project cloudbreak by hortonworks.
the class ClusterProxyServiceTest method testClusterProxyRegistrationWhenCCMDisabled.
@Test
public void testClusterProxyRegistrationWhenCCMDisabled() {
Stack aStack = getAStack();
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain("ipadom");
GatewayConfig gatewayConfig = new GatewayConfig("connectionAddress", "publicAddress", PRIVATE_ADDRESS, 9443, "instanceId", false);
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.isUseCcmV2(), "CCMV2 should not be enabled.");
assertFalse(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should not be enabled");
assertNull(proxyRegistrationReq.getCcmV2Configs(), "CCMV2 config should not be initialized");
assertNull(proxyRegistrationReq.getTunnels(), "CCMV1 tunnel should not be initialized");
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://publicAddress:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.ipadom", List.of("https://publicAddress:9443"), List.of(), null));
}
use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse in project cloudbreak by hortonworks.
the class ClusterProxyServiceTest method testUpdateClusterProxyRegistrationWhenCCMV2OrJumpgate.
@ParameterizedTest
@EnumSource(value = Tunnel.class, names = { "CCMV2", "CCMV2_JUMPGATE" }, mode = EnumSource.Mode.INCLUDE)
public void testUpdateClusterProxyRegistrationWhenCCMV2OrJumpgate(Tunnel ccmv2Mode) {
Stack aStack = getAStack();
aStack.setTunnel(ccmv2Mode);
aStack.setCcmV2AgentCrn("testAgentCrn");
SecurityConfig securityConfig = new SecurityConfig();
securityConfig.setUsePrivateIpToTls(true);
aStack.setSecurityConfig(securityConfig);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain("test.freeipa.domain");
GatewayConfig primaryGateway = new GatewayConfig("primaryAddress", "primaryPublicAddress", "primaryPrivateAddress", ServiceFamilies.GATEWAY.getDefaultPort(), "privateInstanceId", true);
GatewayConfig gatewayConfig1 = new GatewayConfig("connectionAddress1", "publicIpAddress1", PRIVATE_IP_ADDRESS_1, ServiceFamilies.GATEWAY.getDefaultPort(), "testInstanceId1", true);
ReflectionTestUtils.setField(gatewayConfig1, "hostname", "hostname1");
GatewayConfig gatewayConfig2 = new GatewayConfig("connectionAddress2", "publicIpAddress2", PRIVATE_IP_ADDRESS_2, ServiceFamilies.GATEWAY.getDefaultPort(), "testInstanceId2", true);
ReflectionTestUtils.setField(gatewayConfig2, "hostname", "hostname2");
ConfigRegistrationResponse configRegResponse = mock(ConfigRegistrationResponse.class);
when(stackService.getStackById(STACK_ID)).thenReturn(aStack);
when(clusterProxyEnablementService.isClusterProxyApplicable(any())).thenReturn(true);
when(gatewayConfigService.getPrimaryGatewayConfig(aStack)).thenReturn(primaryGateway);
when(gatewayConfigService.getNotDeletedGatewayConfigs(aStack)).thenReturn(List.of(gatewayConfig1, gatewayConfig2));
when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(configRegResponse);
when(freeIpaService.findByStack(aStack)).thenReturn(freeIpa);
when(clusterProxyServiceAvailabilityChecker.isDnsBasedServiceNameAvailable(aStack)).thenReturn(true);
when(serviceEndpointHealthPollingService.pollWithTimeout(any(), any(), anyLong(), anyInt(), anyInt())).thenReturn(null);
when(stackUpdater.updateClusterProxyRegisteredFlag(aStack, true)).thenReturn(aStack);
when(healthCheckAvailabilityChecker.isCdpFreeIpaHeathAgentAvailable(aStack)).thenReturn(true);
ReflectionTestUtils.setField(underTest, "intervalInSecV2", INTERVAL_IN_SEC_V_2);
ReflectionTestUtils.setField(underTest, "healthStatusEndpointV2", HEALTH_STATUS_ENDPOINT_V_2);
ReflectionTestUtils.setField(underTest, "timeoutInSecV2", TIMEOUT_IN_SEC_V_2);
ReflectionTestUtils.setField(underTest, "healthyStatusCodeV2", HEALTHY_STATUS_CODE_V_2);
underTest.updateFreeIpaRegistrationAndWait(STACK_ID, List.of("testInstanceId1", "testInstanceId2"));
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_1, ServiceFamilies.GATEWAY.getDefaultPort(), "testAgentCrn-testInstanceId1", FREEIPA_SERVICE), new CcmV2Config("testAgentCrn", PRIVATE_IP_ADDRESS_2, ServiceFamilies.GATEWAY.getDefaultPort(), "testAgentCrn-testInstanceId2", FREEIPA_SERVICE)), proxyRegistrationReq.getCcmV2Configs(), ccmv2Mode + " config should match");
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://primaryPrivateAddress:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).doesNotContain(new ClusterServiceConfig("freeipa.test.freeipa.domain", List.of("https://primaryPrivateAddress:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("hostname1", List.of("https://privateIpAddress1:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("hostname2", List.of("https://privateIpAddress2:9443"), List.of(), null));
assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.test.freeipa.domain", List.of("https://privateIpAddress1:9443", "https://privateIpAddress2:9443"), null, false, List.of(), null, new ClusterServiceHealthCheck(INTERVAL_IN_SEC_V_2, HEALTH_STATUS_ENDPOINT_V_2, TIMEOUT_IN_SEC_V_2, HEALTHY_STATUS_CODE_V_2)));
}
use of com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse 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)));
}
Aggregations