Search in sources :

Example 1 with CcmV2Exception

use of com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception in project cloudbreak by hortonworks.

the class CcmV2ManagementClient method awaitReadyInvertingProxyForAccount.

public InvertingProxy awaitReadyInvertingProxyForAccount(String requestId, String accountId) {
    return getRetryTemplate().execute(retryContext -> {
        LOGGER.debug("Retrieving InvertingProxy for accountId '{}'", accountId);
        InvertingProxy invertingProxy = grpcCcmV2Client.getOrCreateInvertingProxy(requestId, accountId, ThreadBasedUserCrnProvider.getUserCrn());
        LOGGER.debug("Retrieved InvertingProxy with status '{}' for accountId '{}'", invertingProxy.getStatus(), accountId);
        if (!InvertingProxy.Status.READY.equals(invertingProxy.getStatus())) {
            throw new CcmV2Exception(String.format("InvertingProxy is not available in 'READY' state for accountId '%s'", accountId));
        }
        return invertingProxy;
    }, retryExhausted -> {
        LOGGER.error("Error Retrieving InvertingProxy for accountId '{}', retryCount '{}'", accountId, retryExhausted.getRetryCount());
        throw new CcmV2Exception("Error Retrieving CCM InvertingProxy", retryExhausted.getLastThrowable());
    });
}
Also used : InvertingProxy(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxy) CcmV2Exception(com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception)

Example 2 with CcmV2Exception

use of com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception in project cloudbreak by hortonworks.

the class CcmV2ManagementClient method deregisterInvertingProxyAgent.

public UnregisterAgentResponse deregisterInvertingProxyAgent(String requestId, String agentCrn) {
    return getRetryTemplate().execute(retryContext -> {
        LOGGER.debug("Deregistering Agent for agentCrn '{}'", agentCrn);
        UnregisterAgentResponse unregisterAgentResponse = grpcCcmV2Client.unRegisterAgent(requestId, agentCrn, ThreadBasedUserCrnProvider.getUserCrn());
        LOGGER.debug("Deregistered Agent for agentCrn '{}', unregisterAgentResponse '{}'", agentCrn, unregisterAgentResponse);
        return unregisterAgentResponse;
    }, retryExhausted -> {
        LOGGER.error("Error Deregistering Agent for agentCrn '{}', retryCount '{}'", agentCrn, retryExhausted.getRetryCount());
        throw new CcmV2Exception("Error Deregistering CCM Agent", retryExhausted.getLastThrowable());
    });
}
Also used : UnregisterAgentResponse(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.UnregisterAgentResponse) CcmV2Exception(com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception)

Example 3 with CcmV2Exception

use of com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception in project cloudbreak by hortonworks.

the class DefaultCcmV2ParameterSupplier method unregisterExistingAgent.

private void unregisterExistingAgent(String requestId, String accountId, Optional<String> environmentCrnOpt, String agentKeyId) {
    try {
        List<InvertingProxyAgent> invertingProxyAgents = ccmV2Client.listInvertingProxyAgents(requestId, accountId, environmentCrnOpt);
        Optional<InvertingProxyAgent> registeredAgentWithSameKey = invertingProxyAgents.stream().filter(agent -> agentKeyId.equals(CcmResourceUtil.getKeyId(agent.getAgentCrn()))).findFirst();
        registeredAgentWithSameKey.ifPresent(agent -> ccmV2Client.deregisterInvertingProxyAgent(requestId, agent.getAgentCrn()));
    } catch (CcmV2Exception e) {
        throw new CcmV2Exception("Error in trying to deregister possibly existing CCM Agent", e);
    }
}
Also used : Logger(org.slf4j.Logger) CcmV2ManagementClient(com.sequenceiq.cloudbreak.ccmimpl.ccmv2.CcmV2ManagementClient) LoggerFactory(org.slf4j.LoggerFactory) CcmResourceUtil(com.sequenceiq.cloudbreak.ccm.key.CcmResourceUtil) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) StringUtils(org.apache.commons.lang3.StringUtils) CcmV2ParameterSupplier(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2ParameterSupplier) Inject(javax.inject.Inject) InvertingProxyAgent(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxyAgent) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) List(java.util.List) Component(org.springframework.stereotype.Component) CcmV2Parameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2Parameters) CcmV2Exception(com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception) Optional(java.util.Optional) InvertingProxy(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxy) DefaultCcmV2Parameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmV2Parameters) Nonnull(javax.annotation.Nonnull) InvertingProxyAgent(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxyAgent) CcmV2Exception(com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception)

Example 4 with CcmV2Exception

use of com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception in project cloudbreak by hortonworks.

the class DefaultCcmV2ParameterSupplierTest method unregisterAgentRethrows.

@Test
void unregisterAgentRethrows() {
    setupRegisterInvertingProxyDetails();
    when(ccmV2Client.listInvertingProxyAgents(any(), any(), any())).thenThrow(new CcmV2Exception("internal error"));
    assertThatThrownBy(() -> underTest.getCcmV2Parameters(TEST_ACCOUNT_ID, Optional.of(TEST_ENVIRONMENT_CRN), TEST_GATEWAY_DOMAIN, Crn.fromString(TEST_CLUSTER_CRN).getResource())).hasMessageNotContaining("internal error").isInstanceOf(CcmV2Exception.class);
    verify(ccmV2Client).listInvertingProxyAgents(anyString(), eq(TEST_ACCOUNT_ID), eq(Optional.of(TEST_ENVIRONMENT_CRN)));
    verify(ccmV2Client, never()).registerInvertingProxyAgent(anyString(), eq(TEST_ACCOUNT_ID), eq(Optional.of(TEST_ENVIRONMENT_CRN)), eq(TEST_GATEWAY_DOMAIN), eq(TEST_RESOURCE_ID));
    verify(ccmV2Client, never()).deregisterInvertingProxyAgent(any(), eq(TEST_AGENT_CRN));
}
Also used : CcmV2Exception(com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception) Test(org.junit.jupiter.api.Test)

Example 5 with CcmV2Exception

use of com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception in project cloudbreak by hortonworks.

the class CcmV2ManagementClient method registerInvertingProxyAgent.

public InvertingProxyAgent registerInvertingProxyAgent(String requestId, String accountId, Optional<String> environmentCrnOpt, String domainName, String keyId) {
    return getRetryTemplate().execute(retryContext -> {
        LOGGER.debug("Registering Agent for accountId '{}', environmentCrnOpt: '{}', domainName '{}'", accountId, environmentCrnOpt, domainName);
        InvertingProxyAgent invertingProxyAgent = grpcCcmV2Client.registerAgent(requestId, accountId, environmentCrnOpt, domainName, keyId, ThreadBasedUserCrnProvider.getUserCrn());
        LOGGER.debug("Registered Agent for accountId '{}', environmentCrnOpt: '{}', domainName '{}', invertingProxyAgent '{}'", accountId, environmentCrnOpt, domainName, invertingProxyAgent);
        return invertingProxyAgent;
    }, retryExhausted -> {
        LOGGER.error("Error Registering Agent for accountId '{}', domainName '{}', retryCount '{}'", accountId, domainName, retryExhausted.getRetryCount());
        throw new CcmV2Exception("Error Registering CCM Agent", retryExhausted.getLastThrowable());
    });
}
Also used : InvertingProxyAgent(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxyAgent) CcmV2Exception(com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception)

Aggregations

CcmV2Exception (com.sequenceiq.cloudbreak.ccm.exception.CcmV2Exception)5 InvertingProxy (com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxy)2 InvertingProxyAgent (com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxyAgent)2 UnregisterAgentResponse (com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.UnregisterAgentResponse)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 CcmV2ParameterSupplier (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2ParameterSupplier)1 CcmV2Parameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmV2Parameters)1 DefaultCcmV2Parameters (com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmV2Parameters)1 CcmResourceUtil (com.sequenceiq.cloudbreak.ccm.key.CcmResourceUtil)1 CcmV2ManagementClient (com.sequenceiq.cloudbreak.ccmimpl.ccmv2.CcmV2ManagementClient)1 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)1 List (java.util.List)1 Optional (java.util.Optional)1 Nonnull (javax.annotation.Nonnull)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Test (org.junit.jupiter.api.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Component (org.springframework.stereotype.Component)1