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;
}
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();
}
}
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)));
}
}
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());
}
}
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());
}
}
Aggregations