Search in sources :

Example 11 with ServiceUnavailableException

use of co.cask.cdap.common.ServiceUnavailableException in project cdap by caskdata.

the class HBaseDatasetMetricsReporter method report.

private void report(Map<TableId, HBaseTableUtil.TableStats> tableStats) throws IOException {
    Map<String, String> reverseNamespaceMap = hBaseTableUtil.getHBaseToCDAPNamespaceMap();
    for (Map.Entry<TableId, HBaseTableUtil.TableStats> statEntry : tableStats.entrySet()) {
        String hbaseNamespace = statEntry.getKey().getNamespace();
        String cdapNamespace = reverseNamespaceMap.get(hbaseNamespace);
        // tableNames that doesn't start with user are ignored
        if (NamespaceId.SYSTEM.getNamespace().equals(cdapNamespace)) {
            continue;
        }
        String tableName = statEntry.getKey().getTableName();
        try {
            Collection<DatasetSpecificationSummary> instances = dsFramework.getInstances(new NamespaceId(cdapNamespace));
            for (DatasetSpecificationSummary spec : instances) {
                DatasetSpecification specification = dsFramework.getDatasetSpec(new DatasetId(cdapNamespace, spec.getName()));
                if (specification.isParent(tableName)) {
                    MetricsContext collector = metricsService.getContext(ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, cdapNamespace, Constants.Metrics.Tag.DATASET, spec.getName()));
                    collector.gauge("dataset.size.mb", statEntry.getValue().getTotalSizeMB());
                    break;
                }
            }
        } catch (DatasetManagementException | ServiceUnavailableException e) {
        // No op
        }
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) MetricsContext(co.cask.cdap.api.metrics.MetricsContext) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary) DatasetId(co.cask.cdap.proto.id.DatasetId) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 12 with ServiceUnavailableException

use of co.cask.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(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) URL(java.net.URL)

Example 13 with ServiceUnavailableException

use of co.cask.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();
    dsOpExecutor = injector.getInstance(DatasetOpExecutor.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);
    NamespacedLocationFactory namespacedLocationFactory = injector.getInstance(NamespacedLocationFactory.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.
    namespacedLocationFactory.get(namespaceId).mkdirs();
    exploreClient.addNamespace(namespaceMeta);
}
Also used : DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) DiscoveryExploreClient(co.cask.cdap.explore.client.DiscoveryExploreClient) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) BeforeClass(org.junit.BeforeClass)

Example 14 with ServiceUnavailableException

use of co.cask.cdap.common.ServiceUnavailableException in project cdap by caskdata.

the class ExploreDriver method connect.

@Override
public Connection connect(String url, Properties info) throws SQLException {
    if (!acceptsURL(url)) {
        return null;
    }
    ExploreConnectionParams params = ExploreConnectionParams.parseConnectionUrl(url);
    String authToken = getString(params, ExploreConnectionParams.Info.EXPLORE_AUTH_TOKEN, null);
    String namespace = getString(params, ExploreConnectionParams.Info.NAMESPACE, NamespaceId.DEFAULT.getNamespace());
    boolean sslEnabled = getBoolean(params, ExploreConnectionParams.Info.SSL_ENABLED, false);
    boolean verifySSLCert = getBoolean(params, ExploreConnectionParams.Info.VERIFY_SSL_CERT, true);
    ExploreClient exploreClient = new FixedAddressExploreClient(params.getHost(), params.getPort(), authToken, sslEnabled, verifySSLCert);
    try {
        exploreClient.ping();
    } catch (UnauthenticatedException e) {
        throw new SQLException("Cannot connect to " + url + ", not authenticated.");
    } catch (ServiceUnavailableException | ExploreException e) {
        throw new SQLException("Cannot connect to " + url + ", service not available.");
    }
    return new ExploreConnection(exploreClient, namespace, params);
}
Also used : ExploreClient(co.cask.cdap.explore.client.ExploreClient) FixedAddressExploreClient(co.cask.cdap.explore.client.FixedAddressExploreClient) UnauthenticatedException(co.cask.cdap.common.UnauthenticatedException) SQLException(java.sql.SQLException) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) FixedAddressExploreClient(co.cask.cdap.explore.client.FixedAddressExploreClient) ExploreException(co.cask.cdap.explore.service.ExploreException)

Aggregations

ServiceUnavailableException (co.cask.cdap.common.ServiceUnavailableException)14 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)4 NotFoundException (co.cask.cdap.common.NotFoundException)4 BadRequestException (co.cask.cdap.common.BadRequestException)3 ForbiddenException (co.cask.cdap.common.ForbiddenException)3 MasterServiceManager (co.cask.cdap.common.twill.MasterServiceManager)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 IOException (java.io.IOException)3 Dataset (co.cask.cdap.api.dataset.Dataset)2 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)2 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 Status (ch.qos.logback.core.status.Status)1 StatusListener (ch.qos.logback.core.status.StatusListener)1 DatasetInstantiationException (co.cask.cdap.api.data.DatasetInstantiationException)1 RecordScannable (co.cask.cdap.api.data.batch.RecordScannable)1 RecordWritable (co.cask.cdap.api.data.batch.RecordWritable)1 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)1 MeteredDataset (co.cask.cdap.api.dataset.metrics.MeteredDataset)1