Search in sources :

Example 11 with CcmConnectivityParameters

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;
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) KnownServiceIdentifier(com.sequenceiq.cloudbreak.ccm.endpoint.KnownServiceIdentifier) CcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmParameters) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 12 with 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;
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) CcmV2Parameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2Parameters)

Example 13 with 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);
    }
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 14 with CcmConnectivityParameters

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());
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) ServerParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.ServerParameters) DefaultCcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 15 with CcmConnectivityParameters

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());
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) DefaultCcmV2JumpgateParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmV2JumpgateParameters) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

CcmConnectivityParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters)28 Test (org.junit.jupiter.api.Test)12 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)7 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 Test (org.junit.Test)6 DefaultCcmV2JumpgateParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmV2JumpgateParameters)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)5 CcmParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmParameters)4 CcmV2Parameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2Parameters)4 DefaultCcmParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters)4 DefaultCcmV2Parameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmV2Parameters)4 ScriptParams (com.sequenceiq.cloudbreak.cloud.model.ScriptParams)4 DisplayName (org.junit.jupiter.api.DisplayName)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CcmV2JumpgateParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2JumpgateParameters)3 Optional (java.util.Optional)3 DefaultInstanceParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultInstanceParameters)2 DefaultServerParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultServerParameters)2