Search in sources :

Example 1 with ManagedChannelWrapper

use of com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper in project cloudbreak by hortonworks.

the class DatalakeDrClient method getLastSuccessBackup.

public DatalakeBackupInfo getLastSuccessBackup(String datalakeName, String actorCrn) {
    DatalakeBackupInfo datalakeBackupInfo = null;
    if (!datalakeDrConfig.isConfigured()) {
        return null;
    }
    checkNotNull(datalakeName);
    checkNotNull(actorCrn, "actorCrn should not be null.");
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        ListDatalakeBackupRequest.Builder builder = ListDatalakeBackupRequest.newBuilder().setDatalakeName(datalakeName);
        ListDatalakeBackupResponse response = newStub(channelWrapper.getChannel(), UUID.randomUUID().toString(), actorCrn).listDatalakeBackups(builder.build());
        if (response != null && response.getDatalakeInfoList() != null) {
            datalakeBackupInfo = response.getDatalakeInfoList().stream().filter(backup -> "SUCCESSFUL".equals(backup.getOverallState())).findFirst().orElse(null);
        }
        return datalakeBackupInfo;
    }
}
Also used : RestoreDatalakeRequest(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.RestoreDatalakeRequest) DEFAULT_MAX_MESSAGE_SIZE(io.grpc.internal.GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE) com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc.datalakeDRBlockingStub(com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc.datalakeDRBlockingStub) ManagedChannel(io.grpc.ManagedChannel) LoggerFactory(org.slf4j.LoggerFactory) BackupDatalakeStatusRequest(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.BackupDatalakeStatusRequest) RestoreDatalakeStatusRequest(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.RestoreDatalakeStatusRequest) ListDatalakeBackupRequest(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.ListDatalakeBackupRequest) DatalakeBackupInfo(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.DatalakeBackupInfo) Strings(com.google.common.base.Strings) DatalakeBackupStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeBackupStatusResponse) com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc(com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc) BackupDatalakeRequest(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.BackupDatalakeRequest) GrpcStatusResponseToDatalakeBackupRestoreStatusResponseConverter(com.sequenceiq.cloudbreak.datalakedr.converter.GrpcStatusResponseToDatalakeBackupRestoreStatusResponseConverter) AltusMetadataInterceptor(com.sequenceiq.cloudbreak.grpc.altus.AltusMetadataInterceptor) GrpcUtil(com.sequenceiq.cloudbreak.grpc.util.GrpcUtil) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) UUID(java.util.UUID) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) Component(org.springframework.stereotype.Component) DatalakeDrConfig(com.sequenceiq.cloudbreak.datalakedr.config.DatalakeDrConfig) Optional(java.util.Optional) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) DatalakeRestoreStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse) ListDatalakeBackupResponse(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.ListDatalakeBackupResponse) DatalakeBackupInfo(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.DatalakeBackupInfo) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) ListDatalakeBackupResponse(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.ListDatalakeBackupResponse) ListDatalakeBackupRequest(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.ListDatalakeBackupRequest)

Example 2 with ManagedChannelWrapper

use of com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper in project cloudbreak by hortonworks.

the class GrpcCcmV2Client method registerAgent.

public InvertingProxyAgent registerAgent(String requestId, String accountId, Optional<String> environmentCrnOpt, String domainName, String keyId, String actorCrn) {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        ClusterConnectivityManagementV2BlockingStub client = makeClient(channelWrapper.getChannel(), requestId, actorCrn);
        RegisterAgentRequest.Builder registerAgentRequestBuilder = RegisterAgentRequest.newBuilder().setAccountId(accountId).setDomainName(domainName).setKeyId(keyId);
        environmentCrnOpt.ifPresent(registerAgentRequestBuilder::setEnvironmentCrn);
        RegisterAgentRequest registerAgentRequest = registerAgentRequestBuilder.build();
        LOGGER.debug("Calling registerAgent with params accountId: '{}', environmentCrnOpt: '{}', domainName: '{}', keyId:'{}' ", accountId, environmentCrnOpt, domainName, keyId);
        RegisterAgentResponse registerAgentResponse = client.registerAgent(registerAgentRequest);
        return registerAgentResponse.getInvertingProxyAgent();
    }
}
Also used : RegisterAgentResponse(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.RegisterAgentResponse) RegisterAgentRequest(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.RegisterAgentRequest) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) ClusterConnectivityManagementV2BlockingStub(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Grpc.ClusterConnectivityManagementV2BlockingStub)

Example 3 with ManagedChannelWrapper

use of com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper in project cloudbreak by hortonworks.

the class GrpcMinaSshdManagementClient method generateAndRegisterSshTunnelingKeyPair.

/**
 * Wraps call to generateAndRegisterSshTunnelingKeyPair, with retries to tolerate transient failures.
 *
 * @param requestId         the request ID for the request
 * @param actorCrn          the actor CRN
 * @param accountId         the account ID
 * @param minaSshdServiceId the minasshd service ID
 * @param keyId             the key ID
 * @return the response containing the key pair
 * @throws CcmException         if an exception occurs
 * @throws InterruptedException if the action is interrupted
 */
public MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairResponse generateAndRegisterSshTunnelingKeyPair(String requestId, String actorCrn, String accountId, String minaSshdServiceId, String keyId) throws CcmException, InterruptedException {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        MinaSshdManagementClient client = makeClient(channelWrapper.getChannel(), actorCrn);
        ZonedDateTime waitUntilTime = ZonedDateTime.now(clock).plus(minaSshdManagementClientConfig.getTimeoutMs(), ChronoUnit.MILLIS);
        int pollingIntervalMillis = minaSshdManagementClientConfig.getPollingIntervalMs();
        String actionDescription = "generate tunneling key pair for accountId " + accountId;
        Supplier<CcmException> timeoutExceptionSupplier = () -> new CcmException(String.format("Timed out while trying to %s", actionDescription), true);
        return RetryUtil.performWithRetries(() -> client.generateAndRegisterSshTunnelingKeyPair(requestId, accountId, minaSshdServiceId, keyId), actionDescription, waitUntilTime, pollingIntervalMillis, CcmException.class, timeoutExceptionSupplier, LOGGER);
    }
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ZonedDateTime(java.time.ZonedDateTime) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Example 4 with ManagedChannelWrapper

use of com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper in project cloudbreak by hortonworks.

the class GrpcMinaSshdManagementClient method unregisterSshTunnelingKey.

/**
 * Wraps call to unregisterSshTunnelingKey, with retries to tolerate transient failures.
 *
 * @param requestId the request ID for the request
 * @param actorCrn  the actor CRN
 * @param accountId the account ID
 * @param keyId     the key ID
 * @param minaSshdServiceId minaSshdServiceId
 * @return the response
 * @throws CcmException         if an exception occurs
 * @throws InterruptedException if the action is interrupted
 */
public MinaSshdManagementProto.UnregisterSshTunnelingKeyResponse unregisterSshTunnelingKey(String requestId, String actorCrn, String accountId, String keyId, String minaSshdServiceId) throws CcmException, InterruptedException {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        MinaSshdManagementClient client = makeClient(channelWrapper.getChannel(), actorCrn);
        ZonedDateTime waitUntilTime = ZonedDateTime.now(clock).plus(minaSshdManagementClientConfig.getTimeoutMs(), ChronoUnit.MILLIS);
        int pollingIntervalMillis = minaSshdManagementClientConfig.getPollingIntervalMs();
        String actionDescription = "deregister tunneling key " + keyId;
        Supplier<CcmException> timeoutExceptionSupplier = () -> new CcmException(String.format("Timed out while trying to %s", actionDescription), true);
        return RetryUtil.performWithRetries(() -> client.unregisterSshTunnelingKey(requestId, minaSshdServiceId, keyId), actionDescription, waitUntilTime, pollingIntervalMillis, CcmException.class, timeoutExceptionSupplier, LOGGER);
    }
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ZonedDateTime(java.time.ZonedDateTime) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Example 5 with ManagedChannelWrapper

use of com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper in project cloudbreak by hortonworks.

the class GrpcIdbmmsClient method deleteMappings.

/**
 * Deletes IDBroker mappings in IDBMMS for a particular environment.
 *
 * @param actorCrn the actor CRN; must not be {@code null}
 * @param environmentCrn the environment CRN to delete mappings for; must not be {@code null}
 * @param requestId an optional request ID; must not be {@code null}
 * @throws NullPointerException if either argument is {@code null}
 * @throws IdbmmsOperationException if any problem is encountered during the IDBMMS call processing
 */
public void deleteMappings(String actorCrn, String environmentCrn, Optional<String> requestId) {
    checkNotNull(actorCrn, "actorCrn should not be null.");
    checkNotNull(environmentCrn);
    checkNotNull(requestId, "requestId should not be null.");
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        IdbmmsClient client = makeClient(channelWrapper.getChannel(), actorCrn);
        String effectiveRequestId = requestId.orElse(UUID.randomUUID().toString());
        LOGGER.debug("Deleting IDBroker mappings for environment {} using request ID {}", environmentCrn, effectiveRequestId);
        client.deleteMappings(effectiveRequestId, environmentCrn);
        LOGGER.debug("Deleted IDBroker mappings for environment {}", environmentCrn);
    } catch (RuntimeException e) {
        throw new IdbmmsOperationException(String.format("Error during IDBMMS operation: %s", e.getMessage()), e);
    }
}
Also used : IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Aggregations

ManagedChannelWrapper (com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)32 BackupDatalakeStatusRequest (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.BackupDatalakeStatusRequest)6 RestoreDatalakeStatusRequest (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.RestoreDatalakeStatusRequest)6 AuditProto (com.cloudera.thunderhead.service.audit.AuditProto)4 ClusterConnectivityManagementV2BlockingStub (com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Grpc.ClusterConnectivityManagementV2BlockingStub)4 BackupDatalakeRequest (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.BackupDatalakeRequest)4 RestoreDatalakeRequest (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.RestoreDatalakeRequest)4 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)4 com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc (com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc)3 com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc.datalakeDRBlockingStub (com.cloudera.thunderhead.service.datalakedr.datalakeDRGrpc.datalakeDRBlockingStub)3 DatalakeBackupInfo (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.DatalakeBackupInfo)3 ListDatalakeBackupRequest (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.ListDatalakeBackupRequest)3 ListDatalakeBackupResponse (com.cloudera.thunderhead.service.datalakedr.datalakeDRProto.ListDatalakeBackupResponse)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 Strings (com.google.common.base.Strings)3 CcmException (com.sequenceiq.cloudbreak.ccm.exception.CcmException)3 DatalakeDrConfig (com.sequenceiq.cloudbreak.datalakedr.config.DatalakeDrConfig)3 GrpcStatusResponseToDatalakeBackupRestoreStatusResponseConverter (com.sequenceiq.cloudbreak.datalakedr.converter.GrpcStatusResponseToDatalakeBackupRestoreStatusResponseConverter)3 DatalakeBackupStatusResponse (com.sequenceiq.cloudbreak.datalakedr.model.DatalakeBackupStatusResponse)3 DatalakeRestoreStatusResponse (com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse)3