当前位置: 首页>>代码示例>>Java>>正文


Java ServiceUnavailableException类代码示例

本文整理汇总了Java中org.gbif.api.exception.ServiceUnavailableException的典型用法代码示例。如果您正苦于以下问题:Java ServiceUnavailableException类的具体用法?Java ServiceUnavailableException怎么用?Java ServiceUnavailableException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ServiceUnavailableException类属于org.gbif.api.exception包,在下文中一共展示了ServiceUnavailableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMapFromCube

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Gets the a sorted Map<UUID, Integer> UuidIntMap from a DataCube<UuidIntMap>.
 */
private <O> Map<UUID, Integer> getMapFromCube(DataCubeIo<UuidIntMap> dataCubeIo, DataCube<UuidIntMap> dataCube,
  Dimension<?> dimension, O coordinate) {
  try {
    Optional<UuidIntMap> o = null;
    if (coordinate != null) {
      o = dataCubeIo.get(new ReadBuilder(dataCube).at(dimension, coordinate));
    }
    if (o != null && o.isPresent()) {
      return sortDescending(o.get().getCounts());
    } else {
      return sortDescending(UuidIntMap.EMPTY_MAP.getCounts());
    }
  } catch (Exception e) {
    e.printStackTrace();
    LOG.error("Unable to read from the cube", e);
    throw new ServiceUnavailableException("Unable to read from the taxon occurrence dataset cube", e);
  }
}
 
开发者ID:gbif,项目名称:metrics,代码行数:22,代码来源:OccurrenceCubeResource.java

示例2: findKeysByScope

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Override
public Set<Integer> findKeysByScope(String scope) {
  Set<Integer> keys = Sets.newHashSet();
  // note HTableStore isn't capable of ad hoc scans
  try (Table table = connection.getTable(lookupTableName)) {
    Scan scan = new Scan();
    scan.setCacheBlocks(false);
    scan.setCaching(HBASE_CLIENT_CACHING);
    scan.setFilter(new PrefixFilter(Bytes.toBytes(scope)));
    ResultScanner results = table.getScanner(scan);
    for (Result result : results) {
      byte[] rawKey = result.getValue(Columns.CF, Bytes.toBytes(Columns.LOOKUP_KEY_COLUMN));
      if (rawKey != null) {
        keys.add(Bytes.toInt(rawKey));
      }
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException("Could not read from HBase", e);
  }
  return keys;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:22,代码来源:AbstractHBaseKeyPersistenceService.java

示例3: deleteKeyByUniques

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Override
public void deleteKeyByUniques(Set<String> uniqueStrings, String scope) {
  checkNotNull(uniqueStrings, "uniqueStrings can't be null");
  checkNotNull(scope, "scope can't be null");

  // craft a delete for every uniqueString
  Set<String> lookupKeys = keyBuilder.buildKeys(uniqueStrings, scope);
  List<Delete> keysToDelete = Lists.newArrayListWithCapacity(lookupKeys.size());
  for (String lookupKey : lookupKeys) {
    keysToDelete.add(new Delete(Bytes.toBytes(lookupKey)));
  }
  try (Table lookupTable = connection.getTable(lookupTableName)) {
    if (!keysToDelete.isEmpty()) {
      lookupTable.delete(keysToDelete);
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException("Failure accessing HBase", e);
  }
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:20,代码来源:AbstractHBaseKeyPersistenceService.java

示例4: incrementColumnValue

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
public long incrementColumnValue(T key, String columnName, long value) {
  checkNotNull(key, KEY_CANT_BE_NULL_MSG);
  checkNotNull(columnName, "columnName can't be null");
  checkNotNull(value, "value can't be null");

  long result = 0;
  try (Table table = connection.getTable(tableName)) {
    byte[] byteKey = convertKey(key);
    if (byteKey != null) {
      result = table.incrementColumnValue(byteKey, cfBytes, Bytes.toBytes(columnName), value);
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException(HBASE_READ_ERROR_MSG, e);
  }

  return result;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:18,代码来源:HBaseStore.java

示例5: getRow

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Returns an HBase Result object matching the given key and column name.
 *
 * @param key the primary key of the requested row
 * @param columnName the column value to return
 * @return HBase Result
 *
 * @throws ServiceUnavailableException if there are errors when communicating with HBase
 */
public Result getRow(T key, String columnName) {
  checkNotNull(key, KEY_CANT_BE_NULL_MSG);
  checkNotNull(columnName, "columnName can't be null");

  Result row = null;
  try (Table table = connection.getTable(tableName)) {
    byte[] byteKey = convertKey(key);
    if (byteKey != null) {
      Get get = new Get(byteKey);
      get.addColumn(cfBytes, Bytes.toBytes(columnName));
      row = table.get(get);
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException(HBASE_READ_ERROR_MSG, e);
  }

  return row;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:28,代码来源:HBaseStore.java

示例6: checkAndPut

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Do an HBase checkAndPut - a put that will only be attempted if the checkColumn contains the expected checkValue.
 *
 * @param key the primary key of the row
 * @param putColumn the column where the new value will be stored
 * @param putValue the new value to put
 * @param checkColumn the column to check
 * @param checkValue the expected value of the checkColumn
 * @param ts the timestamp to write on the put (if null, the current timestamp will be used)
 * @return true if condition was met and put was successful, false otherwise
 *
 * @throws ServiceUnavailableException if there are errors when communicating with HBase
 */
public boolean checkAndPut(T key, String putColumn, byte[] putValue, String checkColumn, @Nullable byte[] checkValue,
                           @Nullable Long ts) {
  checkNotNull(key, KEY_CANT_BE_NULL_MSG);
  checkNotNull(putColumn, "putColumn can't be null");
  checkNotNull(putValue, "putValue can't be null");
  checkNotNull(checkColumn, "checkColumn can't be null");

  boolean success = false;
  try (Table table = connection.getTable(tableName)) {
    byte[] byteKey = convertKey(key);
    if (byteKey != null) {
      Put put = new Put(byteKey);
      if (ts != null && ts > 0) {
        put.addColumn(cfBytes, Bytes.toBytes(putColumn), ts, putValue);
      } else {
        put.addColumn(cfBytes, Bytes.toBytes(putColumn), putValue);
      }
      success = table.checkAndPut(byteKey, cfBytes, Bytes.toBytes(checkColumn), checkValue, put);
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException(HBASE_READ_ERROR_MSG, e);
  }

  return success;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:39,代码来源:HBaseStore.java

示例7: getFragment

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Note that the returned fragment here is a String that holds the actual xml or json snippet for this occurrence,
 * and not the Fragment object that is used elsewhere.
 *
 * @param key that identifies an occurrence
 * @return a String holding the original xml or json snippet for this occurrence
 */
@Override
public String getFragment(int key) {
  String fragment = null;
  try (Table table = connection.getTable(TableName.valueOf(occurrenceTableName))) {
    Get get = new Get(Bytes.toBytes(key));
    Result result = table.get(get);
    if (result == null || result.isEmpty()) {
      LOG.info("Couldn't find occurrence for id [{}], returning null", key);
      return null;
    }
    byte[] rawFragment = ExtResultReader.getBytes(result, Columns.column(GbifInternalTerm.fragment));
    if (rawFragment != null) {
      fragment = Bytes.toString(rawFragment);
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException("Could not read from HBase", e);
  }
  return fragment;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:27,代码来源:OccurrencePersistenceServiceImpl.java

示例8: getVerbatim

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Nullable
@Override
public VerbatimOccurrence getVerbatim(@Nullable Integer key) {
  if (key == null) {
    return null;
  }
  VerbatimOccurrence verb = null;
  try (Table table = connection.getTable(TableName.valueOf(occurrenceTableName)))  {
    Get get = new Get(Bytes.toBytes(key));
    Result result = table.get(get);
    if (result == null || result.isEmpty()) {
      LOG.debug("Couldn't find occurrence for key [{}], returning null", key);
      return null;
    }
    verb = OccurrenceBuilder.buildVerbatimOccurrence(result);
  } catch (IOException e) {
    throw new ServiceUnavailableException("Could not read from HBase", e);
  }

  return verb;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:22,代码来源:OccurrencePersistenceServiceImpl.java

示例9: delete

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Override
public void delete(List<Integer> occurrenceKeys) {
  checkNotNull(occurrenceKeys, "occurrenceKeys can't be null");

  try (Table table = connection.getTable(TableName.valueOf(occurrenceTableName)))  {
    List<Delete> deletes = Lists.newArrayListWithExpectedSize(occurrenceKeys.size());
    for (Integer occurrenceKey : occurrenceKeys) {
      if (occurrenceKey != null) {
        deletes.add(new Delete(Bytes.toBytes(occurrenceKey)));
      }
    }
    LOG.debug("Deleting [{}] occurrences", occurrenceKeys.size());
    table.delete(deletes);
  } catch (IOException e) {
    throw new ServiceUnavailableException("Could not access HBase", e);
  }
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:18,代码来源:OccurrencePersistenceServiceImpl.java

示例10: buildRowUpdate

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
<T extends VerbatimOccurrence> RowUpdate buildRowUpdate(T occ) {
  checkNotNull(occ, "occurrence can't be null");
  checkNotNull(occ.getKey(), "occurrence's key can't be null");

  RowUpdate upd = new RowUpdate(occ.getKey());
  try (Table table = connection.getTable(TableName.valueOf(occurrenceTableName))) {
    if (occ instanceof Occurrence) {
      populateVerbatimPutDelete(table, upd, occ, false);
      populateInterpretedPutDelete(upd, (Occurrence) occ);
    } else {
      populateVerbatimPutDelete(table, upd, occ, true);
    }
  } catch (IOException e) {
    throw new ServiceUnavailableException("Could not access HBase", e);
  }

  return upd;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:19,代码来源:OccurrencePersistenceServiceImpl.java

示例11: write

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
/**
 * Returns true if a key was created, false otherwise.
 */
private boolean write(Fragment fragment, boolean createKey, @Nullable Set<UniqueIdentifier> uniqueIds) {
  if (createKey) {
    checkNotNull(uniqueIds, "uniqueIds can't be null if createKey is true");
  }

  boolean keyCreated = false;
  try (Table table = connection.getTable(TableName.valueOf(occurrenceTableName))) {
    if (createKey) {
      KeyLookupResult keyLookupResult = keyService.generateKey(uniqueIds);
      keyCreated = keyLookupResult.isCreated();
      fragment.setKey(keyLookupResult.getKey());
    }
    writeFields(table, fragment);
  } catch (IOException e) {
    throw new ServiceUnavailableException("Could not access HBase", e);
  }

  return keyCreated;
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:23,代码来源:FragmentPersistenceServiceImpl.java

示例12: cancel

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Override
public void cancel(String downloadKey) {
  try {
    Download download = occurrenceDownloadService.get(downloadKey);
    if (download != null) {
      if (RUNNING_STATUSES.contains(download.getStatus())) {
        updateDownloadStatus(download, Download.Status.CANCELLED);
        client.kill(DownloadUtils.downloadToWorkflowId(downloadKey));
        LOG.info("Download {} cancelled", downloadKey);
      }
    } else {
      throw new NotFoundException(String.format("Download %s not found", downloadKey));
    }
  } catch (OozieClientException e) {
    throw new ServiceUnavailableException("Failed to cancel download " + downloadKey, e);
  }
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:18,代码来源:DownloadRequestServiceImpl.java

示例13: create

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Override
public String create(DownloadRequest request) {
  LOG.debug("Trying to create download from request [{}]", request);
  Preconditions.checkNotNull(request);
  try {
    if (!downloadLimitsService.isInDownloadLimits(request.getCreator())) {
      throw new WebApplicationException(Response.status(GbifResponseStatus.ENHANCE_YOUR_CALM.getStatus()).build());
    }
    String jobId = client.run(parametersBuilder.buildWorkflowParameters(request));
    LOG.debug("oozie job id is: [{}]", jobId);
    String downloadId = DownloadUtils.workflowToDownloadId(jobId);
    persistDownload(request, downloadId);
    return downloadId;
  } catch (OozieClientException e) {
    throw new ServiceUnavailableException("Failed to create download job", e);
  }

}
 
开发者ID:gbif,项目名称:occurrence,代码行数:19,代码来源:DownloadRequestServiceImpl.java

示例14: testGetResult

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Test
public void testGetResult() throws ServiceUnavailableException {
  try {
    when(mockedRs.getObject("language_i")).thenReturn("en");
    assertThat(th.getResult(mockedRs, "language_i"), is(Language.ENGLISH));
  } catch (SQLException e) {
  }
}
 
开发者ID:gbif,项目名称:common-mybatis,代码行数:9,代码来源:LanguageTypeHandlerTest.java

示例15: testGetResult

import org.gbif.api.exception.ServiceUnavailableException; //导入依赖的package包/类
@Test
public void testGetResult() throws ServiceUnavailableException {
  try {
    when(mockedRs.getObject("country_i")).thenReturn("dk");
    assertThat(th.getResult(mockedRs, "country_i"), is(Country.DENMARK));
  } catch (SQLException e) {
  }
}
 
开发者ID:gbif,项目名称:common-mybatis,代码行数:9,代码来源:CountryTypeHandlerTest.java


注:本文中的org.gbif.api.exception.ServiceUnavailableException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。