List of usage examples for com.google.common.util.concurrent UncheckedExecutionException UncheckedExecutionException
public UncheckedExecutionException(@Nullable String message, @Nullable Throwable cause)
From source file:org.apache.bookkeeper.tools.cli.commands.bookie.InitCommand.java
@Override public boolean apply(ServerConfiguration conf, CliFlags cmdFlags) { boolean result = false; try {// ww w .j av a 2s . c om result = BookKeeperAdmin.initBookie(conf); } catch (Exception e) { throw new UncheckedExecutionException(e.getMessage(), e); } return result; }
From source file:google.registry.model.pricing.PricingCategory.java
public static Optional<PricingCategory> get(String name) { try {//from ww w. j a v a 2 s . co m return Optional.of(cache.get(name)); } catch (CacheLoader.InvalidCacheLoadException e) { return Optional.absent(); } catch (ExecutionException e) { throw new UncheckedExecutionException("Could not retrieve pricing category named " + name, e); } }
From source file:org.cryptomator.cryptofs.LongFileNameProvider.java
public String inflate(String shortFileName) throws IOException { try {/*from w ww .j ava 2 s .com*/ return ids.get(shortFileName); } catch (ExecutionException e) { if (e.getCause() instanceof IOException || e.getCause() instanceof UncheckedIOException) { throw new IOException(e); } else { throw new UncheckedExecutionException("Unexpected exception", e); } } }
From source file:com.hjz.cache.adapt.GuavaCache.java
@Override public ValueWrapper get(Object key) { if (this.cache instanceof LoadingCache) { try {/*ww w . ja v a 2 s .co m*/ Object value = ((LoadingCache<Object, Object>) this.cache).get(key); return toValueWrapper(value); } catch (ExecutionException ex) { throw new UncheckedExecutionException(ex.getMessage(), ex); } } return super.get(key); }
From source file:google.registry.model.registry.label.CategorizedPremiumList.java
public static Optional<CategorizedPremiumList> get(String name) { try {/* ww w .j a v a2 s . co m*/ return Optional.of(cache.get(name)); } catch (CacheLoader.InvalidCacheLoadException e) { return Optional.absent(); } catch (ExecutionException e) { throw new UncheckedExecutionException("Could not retrieve premium list named " + name, e); } }
From source file:org.apache.bookkeeper.tools.cli.commands.bookie.FormatCommand.java
@Override public boolean apply(ServerConfiguration conf, Flags cmdFlags) { ServerConfiguration bfconf = new ServerConfiguration(conf); boolean result = Bookie.format(bfconf, cmdFlags.nonInteractive, cmdFlags.force); // delete cookie if (cmdFlags.deleteCookie) { try {// w ww . ja va2s. c o m runFunctionWithRegistrationManager(conf, rm -> { try { Versioned<Cookie> cookie = Cookie.readFromRegistrationManager(rm, bfconf); cookie.getValue().deleteFromRegistrationManager(rm, bfconf, cookie.getVersion()); } catch (Exception e) { throw new UncheckedExecutionException(e.getMessage(), e); } return null; }); } catch (MetadataException | ExecutionException e) { throw new UncheckedExecutionException(e.getMessage(), e); } } return result; }
From source file:org.apache.bookkeeper.stream.storage.impl.sc.DefaultStorageContainerController.java
@Override public ClusterAssignmentData computeIdealState(ClusterMetadata clusterMetadata, ClusterAssignmentData currentState, Set<BookieSocketAddress> currentCluster) { if (currentCluster.isEmpty()) { log.info("Current cluster is empty. No alive server is found."); return currentState; }//from w w w . ja v a 2 s. c o m // 1. get current server assignments Map<BookieSocketAddress, Set<Long>> currentServerAssignments; try { currentServerAssignments = currentState.getServersMap().entrySet().stream() .collect(Collectors.toMap(e1 -> { try { return new BookieSocketAddress(e1.getKey()); } catch (UnknownHostException uhe) { log.error("Invalid cluster "); throw new UncheckedExecutionException( "Invalid server found in current assignment map" + e1.getKey(), uhe); } }, e2 -> e2.getValue().getContainersList().stream().collect(Collectors.toSet()))); } catch (UncheckedExecutionException uee) { log.warn("Invalid cluster assignment data is found : {} - {}. Recompute assignment from empty state", currentState, uee.getCause().getMessage()); currentServerAssignments = Maps.newHashMap(); } Set<BookieSocketAddress> currentServersAssigned = currentServerAssignments.keySet(); // 2. if no servers is assigned, initialize the ideal state if (currentServersAssigned.isEmpty()) { return initializeIdealState(clusterMetadata, currentCluster); } // 3. get the cluster diffs Set<BookieSocketAddress> serversAdded = Sets.difference(currentCluster, currentServersAssigned) .immutableCopy(); Set<BookieSocketAddress> serversRemoved = Sets.difference(currentServersAssigned, currentCluster) .immutableCopy(); if (serversAdded.isEmpty() && serversRemoved.isEmpty()) { // cluster is unchanged, assuming the current state is ideal, no re-assignment is required. return currentState; } log.info( "Storage container controller detects cluster changed:\n" + "\t {} servers added: {}\n\t {} servers removed: {}", serversAdded.size(), serversAdded, serversRemoved.size(), serversRemoved); // 4. compute the containers that owned by servers removed. these containers are needed to be reassigned. Set<Long> containersToReassign = currentServerAssignments.entrySet().stream() .filter(serverEntry -> !currentCluster.contains(serverEntry.getKey())) .flatMap(serverEntry -> serverEntry.getValue().stream()).collect(Collectors.toSet()); // 5. use an ordered set as priority deque to sort the servers by the number of assigned containers TreeSet<Pair<BookieSocketAddress, LinkedList<Long>>> assignmentQueue = new TreeSet<>( new ServerAssignmentDataComparator()); for (Map.Entry<BookieSocketAddress, Set<Long>> entry : currentServerAssignments.entrySet()) { BookieSocketAddress host = entry.getKey(); if (!currentCluster.contains(host)) { if (log.isTraceEnabled()) { log.trace("Host {} is not in current cluster anymore", host); } continue; } else { if (log.isTraceEnabled()) { log.trace("Adding host {} to assignment queue", host); } assignmentQueue.add(Pair.of(host, Lists.newLinkedList(entry.getValue()))); } } // 6. add new servers for (BookieSocketAddress server : serversAdded) { assignmentQueue.add(Pair.of(server, Lists.newLinkedList())); } // 7. assign the containers that are needed to be reassigned. for (Long containerId : containersToReassign) { Pair<BookieSocketAddress, LinkedList<Long>> leastLoadedServer = assignmentQueue.pollFirst(); leastLoadedServer.getValue().add(containerId); assignmentQueue.add(leastLoadedServer); } // 8. rebalance the containers if needed int diffAllowed; if (assignmentQueue.size() > clusterMetadata.getNumStorageContainers()) { diffAllowed = 1; } else { diffAllowed = clusterMetadata.getNumStorageContainers() % assignmentQueue.size() == 0 ? 0 : 1; } Pair<BookieSocketAddress, LinkedList<Long>> leastLoaded = assignmentQueue.first(); Pair<BookieSocketAddress, LinkedList<Long>> mostLoaded = assignmentQueue.last(); while (mostLoaded.getValue().size() - leastLoaded.getValue().size() > diffAllowed) { leastLoaded = assignmentQueue.pollFirst(); mostLoaded = assignmentQueue.pollLast(); // move container from mostLoaded to leastLoaded Long containerId = mostLoaded.getValue().removeFirst(); // add the container to the end to avoid balancing this container again. leastLoaded.getValue().addLast(containerId); assignmentQueue.add(leastLoaded); assignmentQueue.add(mostLoaded); leastLoaded = assignmentQueue.first(); mostLoaded = assignmentQueue.last(); } // 9. the new ideal state is computed, finalize it Map<String, ServerAssignmentData> newAssignmentMap = Maps.newHashMap(); assignmentQueue.forEach(assignment -> newAssignmentMap.put(assignment.getKey().toString(), ServerAssignmentData.newBuilder().addAllContainers(assignment.getValue()).build())); return ClusterAssignmentData.newBuilder().putAllServers(newAssignmentMap).build(); }
From source file:google.registry.model.registry.label.BaseDomainLabelList.java
protected static <R> Optional<R> getFromCache(String listName, LoadingCache<String, R> cache) { try {// w ww . j a va 2 s. c o m return Optional.of(cache.get(listName)); } catch (InvalidCacheLoadException e) { return Optional.absent(); } catch (ExecutionException e) { throw new UncheckedExecutionException("Could not retrieve list named " + listName, e); } }
From source file:org.apache.bookkeeper.tests.integration.topologies.BKCluster.java
protected void initNewCluster(String metadataServiceUri) throws Exception { MetadataDrivers.runFunctionWithRegistrationManager( new ServerConfiguration().setMetadataServiceUri(metadataServiceUri), rm -> { try { rm.initNewCluster(); } catch (Exception e) { throw new UncheckedExecutionException("Failed to init a new cluster", e); }// w w w.j a va2 s .co m return null; }); }
From source file:google.registry.model.registry.label.PremiumList.java
/** Returns the PremiumList with the specified name. */ public static Optional<PremiumList> get(String name) { try {// w ww . j a v a 2 s. c o m return Optional.of(cache.get(name)); } catch (InvalidCacheLoadException e) { return Optional.<PremiumList>absent(); } catch (ExecutionException e) { throw new UncheckedExecutionException("Could not retrieve premium list named " + name, e); } }