Search in sources :

Example 1 with ServiceUnavailableException

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;
}
Also used : BadRequestException(io.cdap.cdap.common.BadRequestException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 2 with ServiceUnavailableException

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;
            }
        }
    }
}
Also used : AccessException(io.cdap.cdap.api.security.AccessException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) IOException(java.io.IOException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) Notification(io.cdap.cdap.proto.Notification)

Example 3 with ServiceUnavailableException

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());
    }
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) URL(java.net.URL)

Example 4 with ServiceUnavailableException

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);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) NamespacePathLocator(io.cdap.cdap.common.namespace.NamespacePathLocator) DatasetFramework(io.cdap.cdap.data2.dataset2.DatasetFramework) DiscoveryExploreClient(io.cdap.cdap.explore.client.DiscoveryExploreClient) Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) BeforeClass(org.junit.BeforeClass)

Example 5 with ServiceUnavailableException

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);
    }
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) AccessException(io.cdap.cdap.api.security.AccessException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) IOException(java.io.IOException) AccessException(io.cdap.cdap.api.security.AccessException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) RetryableException(io.cdap.cdap.api.retry.RetryableException) IOException(java.io.IOException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException)

Aggregations

ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)29 IOException (java.io.IOException)12 BadRequestException (io.cdap.cdap.common.BadRequestException)7 NotFoundException (io.cdap.cdap.common.NotFoundException)7 HttpResponse (io.cdap.common.http.HttpResponse)6 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)5 HttpRequest (io.cdap.common.http.HttpRequest)5 URL (java.net.URL)5 Injector (com.google.inject.Injector)4 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)4 Path (javax.ws.rs.Path)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 ForbiddenException (io.cdap.cdap.common.ForbiddenException)3 MasterServiceManager (io.cdap.cdap.common.twill.MasterServiceManager)3 SystemServiceId (io.cdap.cdap.proto.id.SystemServiceId)3 Service (com.google.common.util.concurrent.Service)2 Dataset (io.cdap.cdap.api.dataset.Dataset)2 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)2 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)2 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2