Search in sources :

Example 41 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class RuleKeyBuilderTest method newBuilder.

private RuleKeyBuilder<RuleKey> newBuilder() {
    Map<BuildTarget, BuildRule> ruleMap = ImmutableMap.of(TARGET_1, RULE_1, TARGET_2, RULE_2);
    Map<BuildRule, RuleKey> ruleKeyMap = ImmutableMap.of(RULE_1, RULE_KEY_1, RULE_2, RULE_KEY_2);
    Map<RuleKeyAppendable, RuleKey> appendableKeys = ImmutableMap.of(APPENDABLE_1, RULE_KEY_1, APPENDABLE_2, RULE_KEY_2);
    BuildRuleResolver ruleResolver = new FakeBuildRuleResolver(ruleMap);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(FILESYSTEM.resolve(PATH_1), HashCode.fromInt(0), FILESYSTEM.resolve(PATH_2), HashCode.fromInt(42)), ImmutableMap.of(pathResolver.getAbsoluteArchiveMemberPath(ARCHIVE_PATH_1), HashCode.fromInt(0), pathResolver.getAbsoluteArchiveMemberPath(ARCHIVE_PATH_2), HashCode.fromInt(42)), ImmutableMap.of());
    RuleKeyHasher<HashCode> hasher = new GuavaRuleKeyHasher(Hashing.sha1().newHasher());
    return new RuleKeyBuilder<RuleKey>(ruleFinder, pathResolver, hashCache, hasher) {

        @Override
        protected RuleKeyBuilder<RuleKey> setBuildRule(BuildRule rule) {
            if (rule == IGNORED_RULE) {
                return this;
            }
            return setBuildRuleKey(ruleKeyMap.get(rule));
        }

        @Override
        public RuleKeyBuilder<RuleKey> setAppendableRuleKey(RuleKeyAppendable appendable) {
            if (appendable == IGNORED_APPENDABLE) {
                return this;
            }
            return setAppendableRuleKey(appendableKeys.get(appendable));
        }

        @Override
        protected RuleKeyBuilder<RuleKey> setSourcePath(SourcePath sourcePath) throws IOException {
            if (sourcePath instanceof BuildTargetSourcePath) {
                return setSourcePathAsRule((BuildTargetSourcePath<?>) sourcePath);
            } else {
                return setSourcePathDirectly(sourcePath);
            }
        }

        @Override
        protected RuleKeyBuilder<RuleKey> setNonHashingSourcePath(SourcePath sourcePath) {
            return setNonHashingSourcePathDirectly(sourcePath);
        }

        @Override
        public RuleKey build() {
            return buildRuleKey();
        }
    };
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) RuleKeyAppendable(com.facebook.buck.rules.RuleKeyAppendable)

Example 42 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class ForwardingRuleKeyHasherTest method testForwarding.

@Test
public void testForwarding() {
    String string = "hash";
    HashCode hash = createMock(HashCode.class);
    @SuppressWarnings("unchecked") RuleKeyHasher<String> stringHasher = createStrictMock(RuleKeyHasher.class);
    @SuppressWarnings("unchecked") RuleKeyHasher<HashCode> guavaHasher = createStrictMock(RuleKeyHasher.class);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putKey("42")).andReturn(guavaHasher);
    expect(stringHasher.putKey("42")).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNull()).andReturn(guavaHasher);
    expect(stringHasher.putNull()).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putBoolean(true)).andReturn(guavaHasher);
    expect(stringHasher.putBoolean(true)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putBoolean(false)).andReturn(guavaHasher);
    expect(stringHasher.putBoolean(false)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNumber(42)).andReturn(guavaHasher);
    expect(stringHasher.putNumber(42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNumber((long) 42)).andReturn(guavaHasher);
    expect(stringHasher.putNumber((long) 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNumber((short) 42)).andReturn(guavaHasher);
    expect(stringHasher.putNumber((short) 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNumber((byte) 42)).andReturn(guavaHasher);
    expect(stringHasher.putNumber((byte) 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNumber((float) 42)).andReturn(guavaHasher);
    expect(stringHasher.putNumber((float) 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNumber((double) 42)).andReturn(guavaHasher);
    expect(stringHasher.putNumber((double) 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putString("42")).andReturn(guavaHasher);
    expect(stringHasher.putString("42")).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putBytes(BYTE_ARRAY)).andReturn(guavaHasher);
    expect(stringHasher.putBytes(BYTE_ARRAY)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putPattern(PATTERN)).andReturn(guavaHasher);
    expect(stringHasher.putPattern(PATTERN)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"))).andReturn(guavaHasher);
    expect(stringHasher.putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"))).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putPath(Paths.get("42/42"), HashCode.fromInt(42))).andReturn(guavaHasher);
    expect(stringHasher.putPath(Paths.get("42/42"), HashCode.fromInt(42))).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42))).andReturn(guavaHasher);
    expect(stringHasher.putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42))).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putNonHashingPath("42")).andReturn(guavaHasher);
    expect(stringHasher.putNonHashingPath("42")).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putSourceRoot(SOURCE_ROOT)).andReturn(guavaHasher);
    expect(stringHasher.putSourceRoot(SOURCE_ROOT)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putRuleKey(RULE_KEY_1)).andReturn(guavaHasher);
    expect(stringHasher.putRuleKey(RULE_KEY_1)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putBuildRuleType(BuildRuleType.of("42"))).andReturn(guavaHasher);
    expect(stringHasher.putBuildRuleType(BuildRuleType.of("42"))).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putBuildTarget(TARGET_1)).andReturn(guavaHasher);
    expect(stringHasher.putBuildTarget(TARGET_1)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1))).andReturn(guavaHasher);
    expect(stringHasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1))).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putContainer(RuleKeyHasher.Container.LIST, 42)).andReturn(guavaHasher);
    expect(stringHasher.putContainer(RuleKeyHasher.Container.LIST, 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putContainer(RuleKeyHasher.Container.MAP, 42)).andReturn(guavaHasher);
    expect(stringHasher.putContainer(RuleKeyHasher.Container.MAP, 42)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.SUPPLIER)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.SUPPLIER)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.OPTIONAL)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.OPTIONAL)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.APPENDABLE)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.APPENDABLE)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    expect(guavaHasher.putKey("45")).andReturn(guavaHasher);
    expect(stringHasher.putKey("45")).andReturn(stringHasher);
    expect(guavaHasher.putNull()).andReturn(guavaHasher);
    expect(stringHasher.putNull()).andReturn(stringHasher);
    expect(guavaHasher.putBoolean(true)).andReturn(guavaHasher);
    expect(stringHasher.putBoolean(true)).andReturn(stringHasher);
    expect(guavaHasher.putNumber(45)).andReturn(guavaHasher);
    expect(stringHasher.putNumber(45)).andReturn(stringHasher);
    expect(guavaHasher.putString("45")).andReturn(guavaHasher);
    expect(stringHasher.putString("45")).andReturn(stringHasher);
    expect(guavaHasher.putBytes(BYTE_ARRAY)).andReturn(guavaHasher);
    expect(stringHasher.putBytes(BYTE_ARRAY)).andReturn(stringHasher);
    expect(guavaHasher.putPattern(PATTERN)).andReturn(guavaHasher);
    expect(stringHasher.putPattern(PATTERN)).andReturn(stringHasher);
    expect(guavaHasher.putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"))).andReturn(guavaHasher);
    expect(stringHasher.putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"))).andReturn(stringHasher);
    expect(guavaHasher.putPath(Paths.get("45"), HashCode.fromInt(45))).andReturn(guavaHasher);
    expect(stringHasher.putPath(Paths.get("45"), HashCode.fromInt(45))).andReturn(stringHasher);
    expect(guavaHasher.putArchiveMemberPath(newArchiveMember("45", "45"), HashCode.fromInt(45))).andReturn(guavaHasher);
    expect(stringHasher.putArchiveMemberPath(newArchiveMember("45", "45"), HashCode.fromInt(45))).andReturn(stringHasher);
    expect(guavaHasher.putNonHashingPath("45")).andReturn(guavaHasher);
    expect(stringHasher.putNonHashingPath("45")).andReturn(stringHasher);
    expect(guavaHasher.putSourceRoot(SOURCE_ROOT)).andReturn(guavaHasher);
    expect(stringHasher.putSourceRoot(SOURCE_ROOT)).andReturn(stringHasher);
    expect(guavaHasher.putRuleKey(RULE_KEY_1)).andReturn(guavaHasher);
    expect(stringHasher.putRuleKey(RULE_KEY_1)).andReturn(stringHasher);
    expect(guavaHasher.putBuildRuleType(BuildRuleType.of("45"))).andReturn(guavaHasher);
    expect(stringHasher.putBuildRuleType(BuildRuleType.of("45"))).andReturn(stringHasher);
    expect(guavaHasher.putBuildTarget(TARGET_1)).andReturn(guavaHasher);
    expect(stringHasher.putBuildTarget(TARGET_1)).andReturn(stringHasher);
    expect(guavaHasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1))).andReturn(guavaHasher);
    expect(stringHasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1))).andReturn(stringHasher);
    expect(guavaHasher.putContainer(RuleKeyHasher.Container.LIST, 45)).andReturn(guavaHasher);
    expect(stringHasher.putContainer(RuleKeyHasher.Container.LIST, 45)).andReturn(stringHasher);
    expect(guavaHasher.putContainer(RuleKeyHasher.Container.MAP, 45)).andReturn(guavaHasher);
    expect(stringHasher.putContainer(RuleKeyHasher.Container.MAP, 45)).andReturn(stringHasher);
    expect(guavaHasher.putWrapper(RuleKeyHasher.Wrapper.OPTIONAL)).andReturn(guavaHasher);
    expect(stringHasher.putWrapper(RuleKeyHasher.Wrapper.OPTIONAL)).andReturn(stringHasher);
    expect(guavaHasher.hash()).andReturn(hash);
    expect(stringHasher.hash()).andReturn(string);
    replay(stringHasher, guavaHasher);
    newHasher(guavaHasher, stringHasher).hash();
    newHasher(guavaHasher, stringHasher).putKey("42").hash();
    newHasher(guavaHasher, stringHasher).putNull().hash();
    newHasher(guavaHasher, stringHasher).putBoolean(true).hash();
    newHasher(guavaHasher, stringHasher).putBoolean(false).hash();
    newHasher(guavaHasher, stringHasher).putNumber(42).hash();
    newHasher(guavaHasher, stringHasher).putNumber((long) 42).hash();
    newHasher(guavaHasher, stringHasher).putNumber((short) 42).hash();
    newHasher(guavaHasher, stringHasher).putNumber((byte) 42).hash();
    newHasher(guavaHasher, stringHasher).putNumber((float) 42).hash();
    newHasher(guavaHasher, stringHasher).putNumber((double) 42).hash();
    newHasher(guavaHasher, stringHasher).putString("42").hash();
    newHasher(guavaHasher, stringHasher).putBytes(BYTE_ARRAY).hash();
    newHasher(guavaHasher, stringHasher).putPattern(PATTERN).hash();
    newHasher(guavaHasher, stringHasher).putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c")).hash();
    newHasher(guavaHasher, stringHasher).putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash();
    newHasher(guavaHasher, stringHasher).putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash();
    newHasher(guavaHasher, stringHasher).putNonHashingPath("42").hash();
    newHasher(guavaHasher, stringHasher).putSourceRoot(SOURCE_ROOT).hash();
    newHasher(guavaHasher, stringHasher).putRuleKey(RULE_KEY_1).hash();
    newHasher(guavaHasher, stringHasher).putBuildRuleType(BuildRuleType.of("42")).hash();
    newHasher(guavaHasher, stringHasher).putBuildTarget(TARGET_1).hash();
    newHasher(guavaHasher, stringHasher).putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash();
    newHasher(guavaHasher, stringHasher).putContainer(RuleKeyHasher.Container.LIST, 42).hash();
    newHasher(guavaHasher, stringHasher).putContainer(RuleKeyHasher.Container.MAP, 42).hash();
    newHasher(guavaHasher, stringHasher).putWrapper(RuleKeyHasher.Wrapper.SUPPLIER).hash();
    newHasher(guavaHasher, stringHasher).putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).hash();
    newHasher(guavaHasher, stringHasher).putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT).hash();
    newHasher(guavaHasher, stringHasher).putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT).hash();
    newHasher(guavaHasher, stringHasher).putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE).hash();
    newHasher(guavaHasher, stringHasher).putWrapper(RuleKeyHasher.Wrapper.APPENDABLE).hash();
    newHasher(guavaHasher, stringHasher).putKey("45").putNull().putBoolean(true).putNumber(45).putString("45").putBytes(BYTE_ARRAY).putPattern(PATTERN).putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c")).putPath(Paths.get("45"), HashCode.fromInt(45)).putArchiveMemberPath(newArchiveMember("45", "45"), HashCode.fromInt(45)).putNonHashingPath("45").putSourceRoot(SOURCE_ROOT).putRuleKey(RULE_KEY_1).putBuildRuleType(BuildRuleType.of("45")).putBuildTarget(TARGET_1).putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).putContainer(RuleKeyHasher.Container.LIST, 45).putContainer(RuleKeyHasher.Container.MAP, 45).putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).hash();
}
Also used : HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 43 with HashCode

use of com.google.common.hash.HashCode in project che by eclipse.

the class SHA512PasswordEncryptor method test.

@Override
public boolean test(String password, String passwordHash) {
    requireNonNull(password, "Required non-null password");
    requireNonNull(passwordHash, "Required non-null password's hash");
    // retrieve salt from the hash
    final int passwordHashLength = ENCRYPTED_PASSWORD_BYTES_LENGTH * 2;
    if (passwordHash.length() < passwordHashLength + SALT_BYTES_LENGTH * 2) {
        return false;
    }
    final HashCode saltHash = HashCode.fromString(passwordHash.substring(passwordHashLength));
    // sha1(password + salt)
    final HashCode hash = Hashing.sha512().hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), saltHash.asBytes()));
    // test sha1(password + salt) + salt == passwordHash
    return (hash.toString() + saltHash.toString()).equals(passwordHash);
}
Also used : HashCode(com.google.common.hash.HashCode)

Example 44 with HashCode

use of com.google.common.hash.HashCode in project elastic-job by dangdangdotcom.

the class FailoverService method getAllEligibleJobContexts.

/**
     * 从失效转移队列中获取所有有资格执行的作业上下文.
     *
     * @return 有资格执行的作业上下文集合
     */
public Collection<JobContext> getAllEligibleJobContexts() {
    if (!regCenter.isExisted(FailoverNode.ROOT)) {
        return Collections.emptyList();
    }
    List<String> jobNames = regCenter.getChildrenKeys(FailoverNode.ROOT);
    Collection<JobContext> result = new ArrayList<>(jobNames.size());
    Set<HashCode> assignedTasks = new HashSet<>(jobNames.size() * 10, 1);
    for (String each : jobNames) {
        List<String> taskIdList = regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath(each));
        if (taskIdList.isEmpty()) {
            regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
            continue;
        }
        Optional<CloudJobConfiguration> jobConfig = configService.load(each);
        if (!jobConfig.isPresent()) {
            regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
            continue;
        }
        List<Integer> assignedShardingItems = getAssignedShardingItems(each, taskIdList, assignedTasks);
        if (!assignedShardingItems.isEmpty()) {
            if (jobConfig.isPresent()) {
                result.add(new JobContext(jobConfig.get(), assignedShardingItems, ExecutionType.FAILOVER));
            }
        }
    }
    return result;
}
Also used : HashCode(com.google.common.hash.HashCode) CloudJobConfiguration(com.dangdang.ddframe.job.cloud.scheduler.config.job.CloudJobConfiguration) ArrayList(java.util.ArrayList) JobContext(com.dangdang.ddframe.job.cloud.scheduler.context.JobContext) HashSet(java.util.HashSet)

Example 45 with HashCode

use of com.google.common.hash.HashCode in project graylog2-server by Graylog2.

the class WebInterfaceAssetsResource method getResponse.

private Response getResponse(Request request, String filename, URL resourceUrl, boolean fromPlugin) throws IOException, URISyntaxException {
    final Date lastModified;
    final InputStream stream;
    final HashCode hashCode;
    switch(resourceUrl.getProtocol()) {
        case "file":
            final File file = new File(resourceUrl.toURI());
            lastModified = new Date(file.lastModified());
            stream = new FileInputStream(file);
            hashCode = Files.hash(file, Hashing.sha256());
            break;
        case "jar":
            final URI uri = resourceUrl.toURI();
            final FileSystem fileSystem = fileSystemCache.getUnchecked(uri);
            final java.nio.file.Path path = fileSystem.getPath(pluginPrefixFilename(fromPlugin, filename));
            final FileTime lastModifiedTime = java.nio.file.Files.getLastModifiedTime(path);
            lastModified = new Date(lastModifiedTime.toMillis());
            stream = resourceUrl.openStream();
            hashCode = Resources.asByteSource(resourceUrl).hash(Hashing.sha256());
            break;
        default:
            throw new IllegalArgumentException("Not a JAR or local file: " + resourceUrl);
    }
    final EntityTag entityTag = new EntityTag(hashCode.toString());
    final Response.ResponseBuilder response = request.evaluatePreconditions(lastModified, entityTag);
    if (response != null) {
        return response.build();
    }
    final String contentType = firstNonNull(mimeTypes.getContentType(filename), MediaType.APPLICATION_OCTET_STREAM);
    final CacheControl cacheControl = new CacheControl();
    cacheControl.setMaxAge((int) TimeUnit.DAYS.toSeconds(365));
    cacheControl.setNoCache(false);
    cacheControl.setPrivate(false);
    return Response.ok(stream).header(HttpHeaders.CONTENT_TYPE, contentType).tag(entityTag).cacheControl(cacheControl).lastModified(lastModified).build();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileTime(java.nio.file.attribute.FileTime) URI(java.net.URI) Date(java.util.Date) FileInputStream(java.io.FileInputStream) Response(javax.ws.rs.core.Response) HashCode(com.google.common.hash.HashCode) FileSystem(java.nio.file.FileSystem) EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) File(java.io.File)

Aggregations

HashCode (com.google.common.hash.HashCode)115 Path (java.nio.file.Path)41 Test (org.junit.Test)39 BuildTarget (com.facebook.buck.model.BuildTarget)19 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 IOException (java.io.IOException)12 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 FileHashCache (com.facebook.buck.util.cache.FileHashCache)11 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)10 Hasher (com.google.common.hash.Hasher)10 Map (java.util.Map)8 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)7 SourcePath (com.facebook.buck.rules.SourcePath)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5