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