Search in sources :

Example 76 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hbase by apache.

the class JmxCacheBuster method stop.

/**
   * Stops the clearing of JMX metrics and restarting the Hadoop metrics system. This is needed for
   * some test environments where we manually inject sources or sinks dynamically.
   */
@VisibleForTesting
public static void stop() {
    stopped.set(true);
    ScheduledFuture future = fut.get();
    future.cancel(false);
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 77 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hbase by apache.

the class HMaster method move.

// Public so can be accessed by tests.
@VisibleForTesting
public void move(final byte[] encodedRegionName, final byte[] destServerName) throws HBaseIOException {
    RegionState regionState = assignmentManager.getRegionStates().getRegionState(Bytes.toString(encodedRegionName));
    HRegionInfo hri;
    if (regionState != null) {
        hri = regionState.getRegion();
    } else {
        throw new UnknownRegionException(Bytes.toStringBinary(encodedRegionName));
    }
    ServerName dest;
    if (destServerName == null || destServerName.length == 0) {
        LOG.info("Passed destination servername is null/empty so " + "choosing a server at random");
        final List<ServerName> destServers = this.serverManager.createDestinationServersList(regionState.getServerName());
        dest = balancer.randomAssignment(hri, destServers);
        if (dest == null) {
            LOG.debug("Unable to determine a plan to assign " + hri);
            return;
        }
    } else {
        ServerName candidate = ServerName.valueOf(Bytes.toString(destServerName));
        dest = balancer.randomAssignment(hri, Lists.newArrayList(candidate));
        if (dest == null) {
            LOG.debug("Unable to determine a plan to assign " + hri);
            return;
        }
        if (dest.equals(serverName) && balancer instanceof BaseLoadBalancer && !((BaseLoadBalancer) balancer).shouldBeOnMaster(hri)) {
            // To avoid unnecessary region moving later by balancer. Don't put user
            // regions on master. Regions on master could be put on other region
            // server intentionally by test however.
            LOG.debug("Skipping move of region " + hri.getRegionNameAsString() + " to avoid unnecessary region moving later by load balancer," + " because it should not be on master");
            return;
        }
    }
    if (dest.equals(regionState.getServerName())) {
        LOG.debug("Skipping move of region " + hri.getRegionNameAsString() + " because region already assigned to the same server " + dest + ".");
        return;
    }
    // Now we can do the move
    RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), dest);
    try {
        checkInitialized();
        if (this.cpHost != null) {
            if (this.cpHost.preMove(hri, rp.getSource(), rp.getDestination())) {
                return;
            }
        }
        // warmup the region on the destination before initiating the move. this call
        // is synchronous and takes some time. doing it before the source region gets
        // closed
        serverManager.sendRegionWarmup(rp.getDestination(), hri);
        LOG.info(getClientIdAuditPrefix() + " move " + rp + ", running balancer");
        this.assignmentManager.balance(rp);
        if (this.cpHost != null) {
            this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());
        }
    } catch (IOException ioe) {
        if (ioe instanceof HBaseIOException) {
            throw (HBaseIOException) ioe;
        }
        throw new HBaseIOException(ioe);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) ServerName(org.apache.hadoop.hbase.ServerName) BaseLoadBalancer(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 78 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hbase by apache.

the class AbstractFSWAL method getOldPath.

@VisibleForTesting
Path getOldPath() {
    long currentFilenum = this.filenum.get();
    Path oldPath = null;
    if (currentFilenum > 0) {
        // ComputeFilename will take care of meta wal filename
        oldPath = computeFilename(currentFilenum);
    }
    // I presume if currentFilenum is <= 0, this is first file and null for oldPath if fine?
    return oldPath;
}
Also used : Path(org.apache.hadoop.fs.Path) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 79 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hbase by apache.

the class WALSplitter method split.

// A wrapper to split one log folder using the method used by distributed
// log splitting. Used by tools and unit tests. It should be package private.
// It is public only because TestWALObserver is in a different package,
// which uses this method to do log splitting.
@VisibleForTesting
public static List<Path> split(Path rootDir, Path logDir, Path oldLogDir, FileSystem fs, Configuration conf, final WALFactory factory) throws IOException {
    final FileStatus[] logfiles = SplitLogManager.getFileList(conf, Collections.singletonList(logDir), null);
    List<Path> splits = new ArrayList<>();
    if (logfiles != null && logfiles.length > 0) {
        for (FileStatus logfile : logfiles) {
            WALSplitter s = new WALSplitter(factory, conf, rootDir, fs, null, null, RecoveryMode.LOG_SPLITTING);
            if (s.splitLogFile(logfile, null)) {
                finishSplitLogFile(rootDir, oldLogDir, logfile.getPath(), conf);
                if (s.outputSink.splits != null) {
                    splits.addAll(s.outputSink.splits);
                }
            }
        }
    }
    if (!fs.delete(logDir, true)) {
        throw new IOException("Unable to delete src dir: " + logDir);
    }
    return splits;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) MultipleIOException(org.apache.hadoop.io.MultipleIOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 80 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class EntityGroupFSTimelineStore method createAndInitYarnClient.

/**
   * Create and initialize the YARN Client. Tests may override/mock this.
   * If they return null, then {@link #getAppState(ApplicationId)} MUST
   * also be overridden
   * @param conf configuration
   * @return the yarn client, or null.
   *
   */
@VisibleForTesting
protected YarnClient createAndInitYarnClient(Configuration conf) {
    YarnClient client = YarnClient.createYarnClient();
    client.init(conf);
    return client;
}
Also used : YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)808 IOException (java.io.IOException)135 ArrayList (java.util.ArrayList)67 Map (java.util.Map)52 Path (java.nio.file.Path)47 File (java.io.File)41 HashMap (java.util.HashMap)37 Path (org.apache.hadoop.fs.Path)33 List (java.util.List)29 ImmutableList (com.google.common.collect.ImmutableList)28 Matcher (java.util.regex.Matcher)26 HashSet (java.util.HashSet)23 ImmutableMap (com.google.common.collect.ImmutableMap)21 FileStatus (org.apache.hadoop.fs.FileStatus)21 SourcePath (com.facebook.buck.rules.SourcePath)20 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)19 DFSClient (org.apache.hadoop.hdfs.DFSClient)18 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)18 ImmutableSet (com.google.common.collect.ImmutableSet)17 LinkedHashMap (java.util.LinkedHashMap)17