use of io.cdap.cdap.common.ServiceUnavailableException in project cdap by caskdata.
the class DirectRuntimeRequestValidator method getProgramRunStatus.
@Override
public ProgramRunInfo getProgramRunStatus(ProgramRunId programRunId, HttpRequest request) throws BadRequestException {
accessEnforcer.enforce(programRunId, authenticationContext.getPrincipal(), StandardPermission.GET);
ProgramRunInfo programRunInfo;
try {
programRunInfo = programRunsCache.get(programRunId).orElseThrow(() -> new BadRequestException("Program run " + programRunId + " is not valid"));
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
throw new ServiceUnavailableException(Constants.Service.RUNTIME, e);
}
return programRunInfo;
}
use of io.cdap.cdap.common.ServiceUnavailableException in project cdap by caskdata.
the class MessagingProgramStatePublisher method publish.
public void publish(Notification.Type notificationType, Map<String, String> properties) {
// ProgramRunId is always required in a notification
Notification programStatusNotification = new Notification(notificationType, properties);
int failureCount = 0;
long startTime = -1L;
boolean done = false;
// This should be refactored into a common class for publishing to TMS with a retry strategy
while (!done) {
try {
messagingService.publish(StoreRequestBuilder.of(topicId).addPayload(GSON.toJson(programStatusNotification)).build());
LOG.trace("Published program status notification: {}", programStatusNotification);
done = true;
} catch (IOException | AccessException e) {
throw Throwables.propagate(e);
} catch (TopicNotFoundException | ServiceUnavailableException e) {
// These exceptions are retry-able due to TMS not completely started
if (startTime < 0) {
startTime = System.currentTimeMillis();
}
long retryMillis = retryStrategy.nextRetry(++failureCount, startTime);
if (retryMillis < 0) {
LOG.error("Failed to publish messages to TMS and exceeded retry limit.", e);
throw Throwables.propagate(e);
}
LOG.debug("Failed to publish messages to TMS due to {}. Will be retried in {} ms.", e.getMessage(), retryMillis);
try {
TimeUnit.MILLISECONDS.sleep(retryMillis);
} catch (InterruptedException e1) {
// Something explicitly stopping this thread. Simply just break and reset the interrupt flag.
LOG.warn("Publishing message to TMS interrupted.");
Thread.currentThread().interrupt();
done = true;
}
}
}
}
use of io.cdap.cdap.common.ServiceUnavailableException in project cdap by caskdata.
the class ServiceClient method checkAvailability.
/**
* Checks whether the {@link Service} is active.
*
* @param service ID of the service
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NotFoundException if the app or service could not be found
* @throws ServiceUnavailableException if the service is not available
*/
public void checkAvailability(ServiceId service) throws IOException, UnauthenticatedException, NotFoundException, ServiceUnavailableException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s/available", service.getApplication(), service.getVersion(), service.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_UNAVAILABLE);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(service);
}
if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
throw new ServiceUnavailableException(service.getProgram());
}
}
use of io.cdap.cdap.common.ServiceUnavailableException in project cdap by caskdata.
the class ExploreDisabledTest method start.
@BeforeClass
public static void start() throws Exception {
Injector injector = Guice.createInjector(createInMemoryModules(CConfiguration.create(), new Configuration()));
transactionManager = injector.getInstance(TransactionManager.class);
transactionManager.startAndWait();
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
dsOpExecutor = injector.getInstance(DatasetOpExecutorService.class);
dsOpExecutor.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
exploreClient = injector.getInstance(DiscoveryExploreClient.class);
try {
exploreClient.ping();
Assert.fail("Expected not to be able to ping explore client.");
} catch (ServiceUnavailableException e) {
// expected
}
datasetFramework = injector.getInstance(DatasetFramework.class);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
NamespacePathLocator namespacePathLocator = injector.getInstance(NamespacePathLocator.class);
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespaceId).build();
namespaceAdmin.create(namespaceMeta);
// This happens when you create a namespace via REST APIs. However, since we do not start AppFabricServer in
// Explore tests, simulating that scenario by explicitly calling DatasetFramework APIs.
namespacePathLocator.get(namespaceId).mkdirs();
exploreClient.addNamespace(namespaceMeta);
}
use of io.cdap.cdap.common.ServiceUnavailableException in project cdap by caskdata.
the class AdminEventPublisher method publishMessage.
private void publishMessage(EntityId entityId, MetadataMessage.Type type, Object payload) {
MetadataMessage message = new MetadataMessage(type, entityId, GSON.toJsonTree(payload));
LOG.trace("Publishing message: {}", message);
try {
Retries.supplyWithRetries(() -> {
try {
messagingContext.getMessagePublisher().publish(NamespaceId.SYSTEM.getNamespace(), topic.getTopic(), GSON.toJson(message));
} catch (TopicNotFoundException | ServiceUnavailableException e) {
throw new RetryableException(e);
} catch (IOException | AccessException e) {
throw Throwables.propagate(e);
}
return null;
}, retryStrategy);
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to publish profile metadata request for entity id %s", entityId), e);
}
}
Aggregations