Search in sources :

Example 26 with ManagedChannelWrapper

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

the class GrpcCcmV2Client method listAgents.

public List<InvertingProxyAgent> listAgents(String requestId, String actorCrn, String accountId, Optional<String> environmentCrnOpt) {
    List<InvertingProxyAgent> result = new ArrayList<>();
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        ClusterConnectivityManagementV2BlockingStub client = makeClient(channelWrapper.getChannel(), requestId, actorCrn);
        Builder listAgentsRequestBuilder = ListAgentsRequest.newBuilder();
        environmentCrnOpt.ifPresentOrElse(listAgentsRequestBuilder::setEnvironmentCrn, () -> listAgentsRequestBuilder.setAccountId(accountId));
        ListAgentsRequest listAgentsRequest = listAgentsRequestBuilder.build();
        PageToken nextPageToken = null;
        int page = 0;
        while (page == 0 || nextPageToken.getExclusiveStartKeyStringAttrsCount() > 0 || nextPageToken.getExclusiveStartKeyNumAttrsCount() > 0) {
            ++page;
            LOGGER.debug("Calling listAgents with params accountId: '{}', environment CRN: '{}', page: '{}'", accountId, environmentCrnOpt, page);
            ListAgentsResponse listAgentsResponse = client.listAgents(listAgentsRequest);
            result.addAll(listAgentsResponse.getAgentsList());
            nextPageToken = listAgentsResponse.getNextPageToken();
            listAgentsRequestBuilder.setPageToken(nextPageToken);
            listAgentsRequest = listAgentsRequestBuilder.build();
        }
    }
    return result;
}
Also used : InvertingProxyAgent(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.InvertingProxyAgent) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) Builder(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.ListAgentsRequest.Builder) ArrayList(java.util.ArrayList) ListAgentsRequest(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.ListAgentsRequest) PageToken(com.cloudera.thunderhead.service.common.paging.PagingProto.PageToken) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) ClusterConnectivityManagementV2BlockingStub(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Grpc.ClusterConnectivityManagementV2BlockingStub) ListAgentsResponse(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.ListAgentsResponse)

Example 27 with ManagedChannelWrapper

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

the class GrpcCcmV2Client method getOrCreateInvertingProxy.

public InvertingProxy getOrCreateInvertingProxy(String requestId, String accountId, String actorCrn) {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        ClusterConnectivityManagementV2BlockingStub client = makeClient(channelWrapper.getChannel(), requestId, actorCrn);
        CreateOrGetInvertingProxyRequest invertingProxyRequest = CreateOrGetInvertingProxyRequest.newBuilder().setAccountId(accountId).build();
        LOGGER.debug("Calling getOrCreateInvertingProxy with params accountId: '{}'", accountId);
        CreateOrGetInvertingProxyResponse invertingProxyRequestResponse = client.createOrGetInvertingProxy(invertingProxyRequest);
        return invertingProxyRequestResponse.getInvertingProxy();
    }
}
Also used : CreateOrGetInvertingProxyResponse(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.CreateOrGetInvertingProxyResponse) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) ClusterConnectivityManagementV2BlockingStub(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Grpc.ClusterConnectivityManagementV2BlockingStub) CreateOrGetInvertingProxyRequest(com.cloudera.thunderhead.service.clusterconnectivitymanagementv2.ClusterConnectivityManagementV2Proto.CreateOrGetInvertingProxyRequest)

Example 28 with ManagedChannelWrapper

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

the class GrpcMinaSshdManagementClient method acquireMinaSshdServiceAndWaitUntilReady.

/**
 * Attempts to acquire a minasshd service for the specified account. If it is not available immediately,
 * polls until it is acquires a ready service, is interrupted, times out, or there are no pending minasshd service instances.
 *
 * @param requestId the request ID for the request
 * @param actorCrn  the actor CRN
 * @param accountId the account ID
 * @return the minasshd service
 * @throws InterruptedException if the thread is interrupted
 * @throws CcmException         if the initial acquisition fails, if the timeout is reached, or if all minasshd service instances are in a FAILED state
 */
public MinaSshdService acquireMinaSshdServiceAndWaitUntilReady(String requestId, String actorCrn, String accountId) throws InterruptedException, CcmException {
    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 = "acquire MinaSSHD service for accountId " + accountId;
        Supplier<CcmException> timeoutExceptionSupplier = () -> new CcmException(String.format("Timed out while trying to %s", actionDescription), true);
        // First call acquireMinaSshdService, with retries in case of transient failures.
        MinaSshdService initialService = RetryUtil.performWithRetries(() -> client.acquireMinaSshdService(requestId, accountId), actionDescription, waitUntilTime, pollingIntervalMillis, CcmException.class, timeoutExceptionSupplier, LOGGER);
        // If the minasshd service was pre-existing, it is in the initial call result
        return getValidMinaSshdService(actionDescription, initialService).orElse(awaitValidMinaSshdService(() -> client.listMinaSshdServices(requestId, accountId, Collections.singletonList(initialService.getMinaSshdServiceId())), actionDescription, waitUntilTime, pollingIntervalMillis, timeoutExceptionSupplier).orElseThrow(() -> new CcmException(String.format("Failed while trying to %s", actionDescription), false)));
    }
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ZonedDateTime(java.time.ZonedDateTime) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) MinaSshdService(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.MinaSshdService)

Example 29 with ManagedChannelWrapper

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

the class AuditClient method updateAttemptAuditEventWithResult.

public void updateAttemptAuditEventWithResult(AttemptAuditEventResult attemptAuditEventResult) {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        String requestId = Optional.ofNullable(attemptAuditEventResult.getRequestId()).orElseGet(uuidSupplier());
        AuditProto.AttemptAuditEventResult protoAttemptAuditEventResult = resultConverter.convert(attemptAuditEventResult);
        newStub(channelWrapper.getChannel(), requestId, attemptAuditEventResult.getActorCrn()).updateAttemptAuditEventWithResult(UpdateAttemptAuditEventWithResultRequest.newBuilder().setResult(protoAttemptAuditEventResult).build());
    }
}
Also used : AuditProto(com.cloudera.thunderhead.service.audit.AuditProto) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Example 30 with ManagedChannelWrapper

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

the class AuditClient method createAttemptAuditEvent.

public void createAttemptAuditEvent(AuditEvent auditEvent) {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        String actorCrn = actorUtil.getActorCrn(auditEvent.getActor());
        AuditProto.AuditEvent protoAuditEvent = auditEventConverter.convert(auditEvent);
        newStub(channelWrapper.getChannel(), protoAuditEvent.getRequestId(), actorCrn).createAttemptAuditEvent(CreateAttemptAuditEventRequest.newBuilder().setAuditEvent(protoAuditEvent).build());
    }
}
Also used : AuditProto(com.cloudera.thunderhead.service.audit.AuditProto) 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