Search in sources :

Example 1 with DefaultCcmParameters

use of com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters in project cloudbreak by hortonworks.

the class DefaultCcmParameterSupplier method getBaseCcmParameters.

@Override
public Optional<CcmParameters> getBaseCcmParameters(@Nonnull String actorCrn, @Nonnull String accountId, @Nonnull String keyId) {
    if (grpcMinaSshdManagementClient == null) {
        return Optional.empty();
    }
    String requestId = MDCBuilder.getOrGenerateRequestId();
    try {
        MinaSshdService minaSshdService = grpcMinaSshdManagementClient.acquireMinaSshdServiceAndWaitUntilReady(requestId, Objects.requireNonNull(actorCrn, "actorCrn is null"), Objects.requireNonNull(accountId, "accountId is null"));
        GenerateAndRegisterSshTunnelingKeyPairResponse keyPairResponse = grpcMinaSshdManagementClient.generateAndRegisterSshTunnelingKeyPair(requestId, actorCrn, accountId, minaSshdService.getMinaSshdServiceId(), keyId);
        return Optional.of(new DefaultCcmParameters(createServerParameters(minaSshdService), createInstanceParameters(keyId, keyPairResponse.getEncipheredPrivateKey()), Collections.emptyList()));
    } catch (Exception e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : DefaultCcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters) GenerateAndRegisterSshTunnelingKeyPairResponse(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairResponse) MinaSshdService(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.MinaSshdService)

Example 2 with DefaultCcmParameters

use of com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters 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 3 with DefaultCcmParameters

use of com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters in project cloudbreak by hortonworks.

the class UserDataBuilderTest method testBuildUserDataWithCCM.

@Test
public void testBuildUserDataWithCCM() throws IOException {
    BaseServiceEndpoint serviceEndpoint = new BaseServiceEndpoint(new HostEndpoint("ccm.cloudera.com"));
    DefaultServerParameters serverParameters = new DefaultServerParameters(serviceEndpoint, "pub-key", "mina-id");
    DefaultInstanceParameters instanceParameters = new DefaultInstanceParameters("tunnel-id", "key-id", "private-key");
    DefaultTunnelParameters nginxTunnel = new DefaultTunnelParameters(KnownServiceIdentifier.GATEWAY, 9443);
    DefaultTunnelParameters knoxTunnel = new DefaultTunnelParameters(KnownServiceIdentifier.KNOX, 8443);
    CcmParameters ccmParameters = new DefaultCcmParameters(serverParameters, instanceParameters, List.of(nginxTunnel, knoxTunnel));
    CcmConnectivityParameters ccmConnectivityParameters = new CcmConnectivityParameters(ccmParameters);
    Map<InstanceGroupType, String> userdata = underTest.buildUserData(Platform.platform("AZURE"), "priv-key".getBytes(), "cloudbreak", getPlatformParameters(), "pass", "cert", ccmConnectivityParameters, null);
    String expectedGwScript = FileReaderUtils.readFileFromClasspath("azure-gateway-ccm-init.sh");
    String expectedCoreScript = FileReaderUtils.readFileFromClasspath("azure-core-ccm-init.sh");
    Assert.assertEquals(expectedGwScript, userdata.get(InstanceGroupType.GATEWAY));
    Assert.assertEquals(expectedCoreScript, userdata.get(InstanceGroupType.CORE));
}
Also used : DefaultCcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters) CcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmParameters) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) DefaultCcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) BaseServiceEndpoint(com.sequenceiq.cloudbreak.ccm.endpoint.BaseServiceEndpoint) DefaultInstanceParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultInstanceParameters) HostEndpoint(com.sequenceiq.cloudbreak.ccm.endpoint.HostEndpoint) DefaultServerParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultServerParameters) DefaultTunnelParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultTunnelParameters) Test(org.junit.Test)

Example 4 with DefaultCcmParameters

use of com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters in project cloudbreak by hortonworks.

the class CcmUserDataServiceTest method testFetchAndSaveCcmParametersWhenCcmV1IsEnabled.

@Test
void testFetchAndSaveCcmParametersWhenCcmV1IsEnabled() {
    Stack stack = getAStack();
    stack.setTunnel(Tunnel.CCM);
    DefaultCcmParameters defaultCcmParameters = mock(DefaultCcmParameters.class);
    ServerParameters serverParameters = mock(ServerParameters.class);
    when(crnService.getUserCrn()).thenReturn(TEST_USER_CRN);
    when(ccmParameterSupplier.getCcmParameters(anyString(), anyString(), anyString(), anyMap())).thenReturn(Optional.of(defaultCcmParameters));
    when(defaultCcmParameters.getServerParameters()).thenReturn(serverParameters);
    when(serverParameters.getMinaSshdServiceId()).thenReturn("minaSshServiceId");
    when(stackService.getStackById(stack.getId())).thenReturn(stack);
    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);
    assertEquals("minaSshServiceId", stack.getMinaSshdServiceId(), "Ccm V1 Config should be initialized");
    verify(stackService, times(1)).save(stack);
}
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.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultCcmParameters

use of com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters in project cloudbreak by hortonworks.

the class UserDataBuilderTest method testBuildUserDataWithCCMParams.

@Test
@DisplayName("test if CCM parameters are passed the user data contains them")
void testBuildUserDataWithCCMParams() throws IOException {
    BaseServiceEndpoint serviceEndpoint = new BaseServiceEndpoint(new HostEndpoint("ccm.cloudera.com"));
    DefaultServerParameters serverParameters = new DefaultServerParameters(serviceEndpoint, "pub-key", "mina-id");
    DefaultInstanceParameters instanceParameters = new DefaultInstanceParameters("tunnel-id", "key-id", "private-key");
    DefaultTunnelParameters nginxTunnel = new DefaultTunnelParameters(KnownServiceIdentifier.GATEWAY, 9443);
    CcmParameters ccmParameters = new DefaultCcmParameters(serverParameters, instanceParameters, List.of(nginxTunnel));
    CcmConnectivityParameters ccmConnectivityParameters = new CcmConnectivityParameters(ccmParameters);
    ProxyAuthentication proxyAuthentication = ProxyAuthentication.builder().withUserName("user").withPassword("pwd").build();
    ProxyConfig proxyConfig = ProxyConfig.builder().withServerHost("proxy.host").withServerPort(1234).withProxyAuthentication(proxyAuthentication).withNoProxyHosts("noproxy.com").withProtocol("https").build();
    PlatformParameters platformParameters = mock(PlatformParameters.class);
    ScriptParams scriptParams = mock(ScriptParams.class);
    when(scriptParams.getDiskPrefix()).thenReturn("sd");
    when(scriptParams.getStartLabel()).thenReturn(98);
    when(platformParameters.scriptParams()).thenReturn(scriptParams);
    String userData = underTest.buildUserData(ACCOUNT_ID, environment, Platform.platform("AZURE"), "priv-key".getBytes(), "cloudbreak", platformParameters, "pass", "cert", ccmConnectivityParameters, proxyConfig);
    String expectedUserData = FileReaderUtils.readFileFromClasspath("azure-ccm-init.sh");
    assertEquals(expectedUserData, userData);
}
Also used : DefaultCcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters) ProxyAuthentication(com.sequenceiq.cloudbreak.dto.ProxyAuthentication) ScriptParams(com.sequenceiq.cloudbreak.cloud.model.ScriptParams) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) DefaultCcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters) CcmParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmParameters) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) BaseServiceEndpoint(com.sequenceiq.cloudbreak.ccm.endpoint.BaseServiceEndpoint) DefaultInstanceParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultInstanceParameters) HostEndpoint(com.sequenceiq.cloudbreak.ccm.endpoint.HostEndpoint) DefaultServerParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultServerParameters) DefaultTunnelParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultTunnelParameters) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

DefaultCcmParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmParameters)5 CcmConnectivityParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters)4 Test (org.junit.jupiter.api.Test)3 CcmParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmParameters)2 DefaultInstanceParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultInstanceParameters)2 DefaultServerParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultServerParameters)2 DefaultTunnelParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultTunnelParameters)2 ServerParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.ServerParameters)2 BaseServiceEndpoint (com.sequenceiq.cloudbreak.ccm.endpoint.BaseServiceEndpoint)2 HostEndpoint (com.sequenceiq.cloudbreak.ccm.endpoint.HostEndpoint)2 GenerateAndRegisterSshTunnelingKeyPairResponse (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairResponse)1 MinaSshdService (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.MinaSshdService)1 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)1 ScriptParams (com.sequenceiq.cloudbreak.cloud.model.ScriptParams)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 ProxyAuthentication (com.sequenceiq.cloudbreak.dto.ProxyAuthentication)1 ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)1 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 Test (org.junit.Test)1