-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[app_discovery] app revision meta report
- Loading branch information
Showing
26 changed files
with
1,349 additions
and
4 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
core/src/main/java/com/alipay/sofa/registry/core/model/AppRevisionInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.core.model; | ||
|
||
import java.io.Serializable; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class AppRevisionInterface implements Serializable { | ||
public String dataId; | ||
public String group; | ||
public String instanceId; | ||
public Map<String, List<String>> serviceParams; | ||
|
||
public AppRevisionInterface() { | ||
serviceParams = new HashMap<>(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
core/src/main/java/com/alipay/sofa/registry/core/model/AppRevisionKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.core.model; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
public class AppRevisionKey implements Comparable<AppRevisionKey>, Serializable { | ||
String appname; | ||
String revision; | ||
|
||
public AppRevisionKey(String appname, String revision) { | ||
this.appname = appname; | ||
this.revision = revision; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
AppRevisionKey that = (AppRevisionKey) o; | ||
return Objects.equals(appname, that.appname) && Objects.equals(revision, that.revision); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(appname, revision); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return appname + "@" + revision; | ||
} | ||
|
||
@Override | ||
public int compareTo(AppRevisionKey o) { | ||
return toString().compareTo(o.toString()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
core/src/main/java/com/alipay/sofa/registry/core/model/AppRevisionRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.core.model; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class AppRevisionRegister implements Serializable { | ||
public String revision; | ||
public String appname; | ||
public Map<String, String> baseParams; | ||
public List<AppRevisionInterface> interfaces; | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/alipay/sofa/registry/common/model/metaserver/CheckRevisionsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.common.model.metaserver; | ||
|
||
import java.io.Serializable; | ||
|
||
public class CheckRevisionsRequest implements Serializable { | ||
public String keysDigest; | ||
|
||
public CheckRevisionsRequest(String keysDigest) { | ||
this.keysDigest = keysDigest; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...src/main/java/com/alipay/sofa/registry/common/model/metaserver/FetchRevisionsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.common.model.metaserver; | ||
|
||
import com.alipay.sofa.registry.core.model.AppRevisionKey; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
public class FetchRevisionsRequest implements Serializable { | ||
public List<AppRevisionKey> keys; | ||
|
||
public FetchRevisionsRequest(List<AppRevisionKey> keys) { | ||
this.keys = keys; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
server/common/util/src/main/java/com/alipay/sofa/registry/util/RevisionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.util; | ||
|
||
import com.alipay.sofa.registry.core.model.AppRevisionKey; | ||
import org.springframework.util.DigestUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RevisionUtils { | ||
public static String revisionsDigest(List<AppRevisionKey> keys) { | ||
Collections.sort(keys); | ||
StringBuffer sb = new StringBuffer(); | ||
for (AppRevisionKey key : keys) { | ||
sb.append(key.toString()); | ||
} | ||
return DigestUtils.md5DigestAsHex(sb.toString().getBytes()); | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
server/common/util/src/main/java/com/alipay/sofa/registry/util/SingleFlight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.registry.util; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
/** | ||
* SingleFlight implements call deduplication for equal keys. | ||
* <p/> | ||
* Example: | ||
* <pre> | ||
* public Result expensiveOperation(final Parameters parameters) throws Exception { | ||
* return singleFlight.execute(parameters, new Callable<Result>() { | ||
* @Override | ||
* public Result call() { | ||
* return expensiveOperationImpl(parameters); | ||
* } | ||
* }); | ||
* } | ||
* | ||
* private Result expensiveOperationImpl(Parameters parameters) { | ||
* // the real implementation | ||
* } | ||
* </pre> | ||
*/ | ||
public class SingleFlight { | ||
|
||
private final ConcurrentMap<Object, Call> calls = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Execute a {@link Callable} if no other calls for the same {@code key} are currently running. | ||
* Concurrent calls for the same {@code key} result in one caller invoking the {@link Callable} and sharing the result | ||
* with the other callers. | ||
* <p/> | ||
* The result of an invocation is not cached, only concurrent calls share the same result. | ||
* | ||
* @param key A unique identification of the method call. | ||
* The {@code key} must be uniquely identifiable by it's {@link Object#hashCode()} and {@link Object#equals(Object)} methods. | ||
* @param callable The {@link Callable} where the result can be obtained from. | ||
* @return The result of invoking the {@link Callable}. | ||
* @throws Exception The {@link Exception} which was thrown by the {@link Callable}. | ||
* Alternatively a {@link InterruptedException} can be thrown if | ||
* the executing {@link Thread} was interrupted while waiting for the result. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <V> V execute(Object key, Callable<V> callable) throws Exception { | ||
Call<V> call = calls.get(key); | ||
if (call == null) { | ||
call = new Call<>(); | ||
Call<V> other = calls.putIfAbsent(key, call); | ||
if (other == null) { | ||
try { | ||
return call.exec(callable); | ||
} finally { | ||
calls.remove(key); | ||
} | ||
} else { | ||
call = other; | ||
} | ||
} | ||
return call.await(); | ||
} | ||
|
||
private static class Call<V> { | ||
|
||
private final Object lock = new Object(); | ||
private boolean finished; | ||
private V result; | ||
private Exception exc; | ||
|
||
void finished(V result, Exception exc) { | ||
synchronized (lock) { | ||
this.finished = true; | ||
this.result = result; | ||
this.exc = exc; | ||
lock.notifyAll(); | ||
} | ||
} | ||
|
||
V await() throws Exception { | ||
synchronized (lock) { | ||
while (!finished) { | ||
lock.wait(); | ||
} | ||
if (exc != null) { | ||
throw exc; | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
V exec(Callable<V> callable) throws Exception { | ||
V result = null; | ||
Exception exc = null; | ||
try { | ||
result = callable.call(); | ||
return result; | ||
} catch (Exception e) { | ||
exc = e; | ||
throw e; | ||
} finally { | ||
finished(result, exc); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>registry-server-parent</artifactId> | ||
<version>5.5.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>registry-consistency</artifactId> | ||
|
||
<properties> | ||
<main.user.dir>../../</main.user.dir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
Oops, something went wrong.