use of com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters in project cloudbreak by hortonworks.
the class CcmUserDataService method getCcmConnectivityParameters.
private CcmConnectivityParameters getCcmConnectivityParameters(Stack stack) {
CcmConnectivityParameters ccmConnectivityParameters;
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
String actorCrn = Objects.requireNonNull(userCrn, "userCrn is null");
ImmutableMap.Builder<KnownServiceIdentifier, Integer> builder = ImmutableMap.builder();
int gatewayPort = Optional.ofNullable(stack.getGatewayPort()).orElse(ServiceFamilies.GATEWAY.getDefaultPort());
builder.put(KnownServiceIdentifier.GATEWAY, gatewayPort);
// Optionally configure a tunnel for (nginx fronting) Knox
if (stack.getCluster().getGateway() != null) {
// JSA TODO Do we support a non-default port for the nginx that fronts Knox?
builder.put(KnownServiceIdentifier.KNOX, ServiceFamilies.KNOX.getDefaultPort());
}
Map<KnownServiceIdentifier, Integer> tunneledServicePorts = builder.build();
CcmParameters ccmV1Parameters = ccmParameterSupplier.getCcmParameters(actorCrn, ThreadBasedUserCrnProvider.getAccountId(), CcmResourceUtil.getKeyId(stack.getResourceCrn()), tunneledServicePorts).orElse(null);
ccmConnectivityParameters = new CcmConnectivityParameters(ccmV1Parameters);
saveCcmV1Config(stack.getId(), ccmV1Parameters);
return ccmConnectivityParameters;
}
use of com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters in project cloudbreak by hortonworks.
the class CcmUserDataService method getCcmV2ConnectivityParameters.
private CcmConnectivityParameters getCcmV2ConnectivityParameters(Stack stack) {
String generatedGatewayFqdn = getGatewayFqdn(stack);
CcmV2Parameters ccmV2Parameters = ccmV2ParameterSupplier.getCcmV2Parameters(ThreadBasedUserCrnProvider.getAccountId(), Optional.empty(), generatedGatewayFqdn, CcmResourceUtil.getKeyId(stack.getResourceCrn()));
CcmConnectivityParameters ccmConnectivityParameters = new CcmConnectivityParameters(ccmV2Parameters);
saveCcmV2Config(stack.getId(), ccmV2Parameters);
return ccmConnectivityParameters;
}
use of com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters in project cloudbreak by hortonworks.
the class UserDataService method createUserData.
public void createUserData(Long stackId) throws CloudbreakImageNotFoundException {
Stack stack = stackService.getByIdWithLists(stackId);
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> connector.getPlatformParameters(stack, userCrn));
SecurityConfig securityConfig = securityConfigService.generateAndSaveSecurityConfig(stack);
stack.setSecurityConfig(securityConfig);
stackService.save(stack);
SaltSecurityConfig saltSecurityConfig = securityConfig.getSaltSecurityConfig();
String cbPrivKey = saltSecurityConfig.getSaltBootSignPrivateKey();
byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(new String(Base64.decodeBase64(cbPrivKey)));
String sshUser = stack.getStackAuthentication().getLoginUserName();
String cbCert = securityConfig.getClientCert();
String saltBootPassword = saltSecurityConfig.getSaltBootPassword();
try {
PlatformParameters platformParameters = platformParametersFuture.get();
CcmConnectivityParameters ccmParameters = ccmUserDataService.fetchAndSaveCcmParameters(stack);
Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(Platform.platform(stack.getCloudPlatform()), cbSshKeyDer, sshUser, platformParameters, saltBootPassword, cbCert, ccmParameters, proxyConfig.orElse(null));
imageService.decorateImageWithUserDataForStack(stack, userData);
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Failed to get Platform parmaters", e);
throw new GetCloudParameterException("Failed to get Platform parmaters", e);
}
}
use of com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters in project cloudbreak by hortonworks.
the class CcmUserDataServiceTest method testFetchAndSaveCcmParametersWhenCcmV1IsEnabled.
@Test
public void testFetchAndSaveCcmParametersWhenCcmV1IsEnabled() {
Stack stack = getAStack();
stack.setTunnel(Tunnel.CCM);
DefaultCcmParameters defaultCcmParameters = mock(DefaultCcmParameters.class);
ServerParameters mockServerParameters = mock(ServerParameters.class);
when(ccmParameterSupplier.getCcmParameters(anyString(), anyString(), anyString(), anyMap())).thenReturn(Optional.of(defaultCcmParameters));
when(defaultCcmParameters.getServerParameters()).thenReturn(mockServerParameters);
when(mockServerParameters.getMinaSshdServiceId()).thenReturn("minaSshdServiceId");
CcmConnectivityParameters ccmParameters = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.fetchAndSaveCcmParameters(stack));
assertEquals(CcmConnectivityMode.CCMV1, ccmParameters.getConnectivityMode(), "CCM V1 should be enabled.");
assertEquals(defaultCcmParameters, ccmParameters.getCcmParameters(), "CCM Parameters should match.");
verify(ccmParameterSupplier, times(1)).getCcmParameters(anyString(), anyString(), anyString(), anyMap());
verifyNoInteractions(ccmV2ParameterSupplier);
verify(stackService, times(1)).setMinaSshdServiceIdByStackId(100L, "minaSshdServiceId");
verify(stackService, never()).setCcmV2AgentCrnByStackId(any(), any());
}
use of com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters in project cloudbreak by hortonworks.
the class CcmUserDataServiceTest method testFetchAndSaveCcmParametersWhenCcmV2JumpgateIsEnabled.
@Test
void testFetchAndSaveCcmParametersWhenCcmV2JumpgateIsEnabled() {
Stack stack = getAStack();
stack.setTunnel(Tunnel.CCMV2_JUMPGATE);
DefaultCcmV2JumpgateParameters defaultCcmV2JumpgateParameters = new DefaultCcmV2JumpgateParameters();
CcmConnectivityParameters ccmParameters = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.fetchAndSaveCcmParameters(stack));
assertEquals(CcmConnectivityMode.CCMV2_JUMPGATE, ccmParameters.getConnectivityMode(), "CCM V2 Jumpgate should be enabled.");
assertThat(ccmParameters.getCcmV2JumpgateParameters()).withFailMessage("CCM V2 Jumpgate Parameters should match.").isEqualToComparingFieldByField(defaultCcmV2JumpgateParameters);
verifyNoInteractions(ccmParameterSupplier);
verify(stackService, never()).setCcmV2AgentCrnByStackId(anyLong(), anyString());
verify(stackService, never()).setMinaSshdServiceIdByStackId(any(), any());
}
Aggregations