refact: unify LF line separator

Change-Id: I3f38685af534468a51b79b7f45d24fdb30a74f34
This commit is contained in:
imbajin 2023-05-06 19:21:16 +08:00
parent d97ba4cb51
commit 08f560f388
10 changed files with 1034 additions and 1034 deletions

View File

@ -1,34 +1,34 @@
package org.apache.hugegraph.pd.meta;
import com.baidu.hugegraph.pd.common.HgAssert;
import com.baidu.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import com.baidu.hugegraph.pd.grpc.Metapb;
import java.util.List;
/**
* @author lynn.bond@hotmail.com on 2022/2/10
*/
public class QueueStore extends MetadataRocksDBStore {
QueueStore(PDConfig pdConfig) {
super(pdConfig);
}
public void addItem(Metapb.QueueItem queueItem) throws PDException {
HgAssert.isArgumentNotNull(queueItem, "queueItem");
byte[] key = MetadataKeyHelper.getQueueItemKey(queueItem.getItemId());
put(key, queueItem.toByteString().toByteArray());
}
public void removeItem(String itemId) throws PDException {
remove(MetadataKeyHelper.getQueueItemKey(itemId));
}
public List<Metapb.QueueItem> getQueue() throws PDException {
byte[] prefix = MetadataKeyHelper.getQueueItemPrefix();
return scanPrefix(Metapb.QueueItem.parser(), prefix);
}
}
package org.apache.hugegraph.pd.meta;
import com.baidu.hugegraph.pd.common.HgAssert;
import com.baidu.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import com.baidu.hugegraph.pd.grpc.Metapb;
import java.util.List;
/**
* @author lynn.bond@hotmail.com on 2022/2/10
*/
public class QueueStore extends MetadataRocksDBStore {
QueueStore(PDConfig pdConfig) {
super(pdConfig);
}
public void addItem(Metapb.QueueItem queueItem) throws PDException {
HgAssert.isArgumentNotNull(queueItem, "queueItem");
byte[] key = MetadataKeyHelper.getQueueItemKey(queueItem.getItemId());
put(key, queueItem.toByteString().toByteArray());
}
public void removeItem(String itemId) throws PDException {
remove(MetadataKeyHelper.getQueueItemKey(itemId));
}
public List<Metapb.QueueItem> getQueue() throws PDException {
byte[] prefix = MetadataKeyHelper.getQueueItemPrefix();
return scanPrefix(Metapb.QueueItem.parser(), prefix);
}
}

View File

@ -1,99 +1,99 @@
package org.apache.hugegraph.pd.metrics;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.grpc.Metapb;
import org.apache.hugegraph.pd.service.PDService;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author lynn.bond@hotmail.com on 2022/1/5
*/
@Component
@Slf4j
public final class PDMetrics {
public final static String PREFIX = "hg";
private final static AtomicLong graphs = new AtomicLong(0);
private MeterRegistry registry;
@Autowired
private PDService pdService;
public synchronized void init(MeterRegistry meterRegistry) {
if (registry == null) {
registry = meterRegistry;
registerMeters();
}
}
private void registerMeters() {
Gauge.builder(PREFIX + ".up", () -> 1).register(registry);
Gauge.builder(PREFIX + ".graphs", () -> updateGraphs())
.description("Number of graphs registered in PD")
.register(registry);
Gauge.builder(PREFIX + ".stores", () -> updateStores())
.description("Number of stores registered in PD")
.register(registry);
}
private long updateGraphs() {
long buf = getGraphs();
if (buf != graphs.get()) {
graphs.set(buf);
registerGraphMetrics();
}
return buf;
}
private long updateStores() {
return getStores();
}
private long getGraphs() {
return getGraphMetas().size();
}
private long getStores(){
try {
return this.pdService.getStoreNodeService().getStores(null).size();
} catch (PDException e) {
log.error(e.getMessage(),e);
e.printStackTrace();
}
return 0;
}
private List<Metapb.Graph> getGraphMetas(){
try {
return this.pdService.getPartitionService().getGraphs();
} catch (PDException e) {
log.error(e.getMessage(),e);
}
return Collections.EMPTY_LIST;
}
private void registerGraphMetrics(){
this.getGraphMetas().forEach(meta->{
Gauge.builder(PREFIX + ".partitions",this.pdService.getPartitionService()
,e-> e.getPartitions(meta.getGraphName()).size())
.description("Number of partitions assigned to a graph")
.tag("graph",meta.getGraphName())
.register(this.registry);
});
}
}
package org.apache.hugegraph.pd.metrics;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.grpc.Metapb;
import org.apache.hugegraph.pd.service.PDService;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author lynn.bond@hotmail.com on 2022/1/5
*/
@Component
@Slf4j
public final class PDMetrics {
public final static String PREFIX = "hg";
private final static AtomicLong graphs = new AtomicLong(0);
private MeterRegistry registry;
@Autowired
private PDService pdService;
public synchronized void init(MeterRegistry meterRegistry) {
if (registry == null) {
registry = meterRegistry;
registerMeters();
}
}
private void registerMeters() {
Gauge.builder(PREFIX + ".up", () -> 1).register(registry);
Gauge.builder(PREFIX + ".graphs", () -> updateGraphs())
.description("Number of graphs registered in PD")
.register(registry);
Gauge.builder(PREFIX + ".stores", () -> updateStores())
.description("Number of stores registered in PD")
.register(registry);
}
private long updateGraphs() {
long buf = getGraphs();
if (buf != graphs.get()) {
graphs.set(buf);
registerGraphMetrics();
}
return buf;
}
private long updateStores() {
return getStores();
}
private long getGraphs() {
return getGraphMetas().size();
}
private long getStores(){
try {
return this.pdService.getStoreNodeService().getStores(null).size();
} catch (PDException e) {
log.error(e.getMessage(),e);
e.printStackTrace();
}
return 0;
}
private List<Metapb.Graph> getGraphMetas(){
try {
return this.pdService.getPartitionService().getGraphs();
} catch (PDException e) {
log.error(e.getMessage(),e);
}
return Collections.EMPTY_LIST;
}
private void registerGraphMetrics(){
this.getGraphMetas().forEach(meta->{
Gauge.builder(PREFIX + ".partitions",this.pdService.getPartitionService()
,e-> e.getPartitions(meta.getGraphName()).size())
.description("Number of partitions assigned to a graph")
.tag("graph",meta.getGraphName())
.register(this.registry);
});
}
}

View File

@ -1,72 +1,72 @@
package org.apache.hugegraph.pd.model;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author lynn.bond@hotmail.com on 2022/2/14
*/
public class PromTargetsModel {
private static final String LABEL_METRICS_PATH = "__metrics_path__";
private static final String LABEL_SCHEME = "__scheme__";
private static final String LABEL_JOB_NAME = "job";
private static final String LABEL_CLUSTER = "cluster";
private Set<String> targets = new HashSet<>();
private Map<String, String> labels = new HashMap<>();
public static PromTargetsModel of() {
return new PromTargetsModel();
}
private PromTargetsModel() {}
public Set<String> getTargets() {
return targets;
}
public Map<String, String> getLabels() {
return labels;
}
public PromTargetsModel addTarget(String target) {
if (target == null) return this;
this.targets.add(target);
return this;
}
public PromTargetsModel setTargets(Set<String> targets) {
if (targets != null) {
this.targets = targets;
}
return this;
}
public PromTargetsModel setMetricsPath(String path) {
return this.addLabel(LABEL_METRICS_PATH, path);
}
public PromTargetsModel setScheme(String scheme) {
return this.addLabel(LABEL_SCHEME, scheme);
}
public PromTargetsModel setClusterId(String clusterId){
return this.addLabel(LABEL_CLUSTER,clusterId);
}
public PromTargetsModel addLabel(String label, String value) {
if (label == null || value == null) return this;
this.labels.put(label, value);
return this;
}
@Override
public String toString() {
return "PromTargetModel{" +
"targets=" + targets +
", labels=" + labels +
'}';
}
}
package org.apache.hugegraph.pd.model;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author lynn.bond@hotmail.com on 2022/2/14
*/
public class PromTargetsModel {
private static final String LABEL_METRICS_PATH = "__metrics_path__";
private static final String LABEL_SCHEME = "__scheme__";
private static final String LABEL_JOB_NAME = "job";
private static final String LABEL_CLUSTER = "cluster";
private Set<String> targets = new HashSet<>();
private Map<String, String> labels = new HashMap<>();
public static PromTargetsModel of() {
return new PromTargetsModel();
}
private PromTargetsModel() {}
public Set<String> getTargets() {
return targets;
}
public Map<String, String> getLabels() {
return labels;
}
public PromTargetsModel addTarget(String target) {
if (target == null) return this;
this.targets.add(target);
return this;
}
public PromTargetsModel setTargets(Set<String> targets) {
if (targets != null) {
this.targets = targets;
}
return this;
}
public PromTargetsModel setMetricsPath(String path) {
return this.addLabel(LABEL_METRICS_PATH, path);
}
public PromTargetsModel setScheme(String scheme) {
return this.addLabel(LABEL_SCHEME, scheme);
}
public PromTargetsModel setClusterId(String clusterId){
return this.addLabel(LABEL_CLUSTER,clusterId);
}
public PromTargetsModel addLabel(String label, String value) {
if (label == null || value == null) return this;
this.labels.put(label, value);
return this;
}
@Override
public String toString() {
return "PromTargetModel{" +
"targets=" + targets +
", labels=" + labels +
'}';
}
}

View File

@ -1,157 +1,157 @@
package org.apache.hugegraph.pd.notice;
import com.baidu.hugegraph.pd.common.HgAssert;
import lombok.extern.slf4j.Slf4j;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* @author lynn.bond@hotmail.com on 2022/2/10
*/
@Slf4j
public class NoticeBroadcaster {
private long noticeId;
private String durableId;
private Supplier<Long> noticeSupplier;
private Supplier<String> durableSupplier;
private Function<String, Boolean> removeFunction;
private int state; //0=ready; 1=notified; 2=done ack; -1=error
private int counter;
private long timestamp;
public static NoticeBroadcaster of(Supplier<Long> noticeSupplier) {
HgAssert.isArgumentNotNull(noticeSupplier, "noticeSupplier");
return new NoticeBroadcaster(noticeSupplier);
}
private NoticeBroadcaster(Supplier<Long> noticeSupplier) {
this.noticeSupplier = noticeSupplier;
this.timestamp = System.currentTimeMillis();
}
public NoticeBroadcaster setDurableSupplier(Supplier<String> durableSupplier) {
this.durableSupplier = durableSupplier;
return this;
}
public NoticeBroadcaster setRemoveFunction(Function<String, Boolean> removeFunction) {
this.removeFunction = removeFunction;
return this;
}
public NoticeBroadcaster notifying() {
if (this.state >= 2) {
log.warn("Aborted notifying as ack has done. notice: {}", this);
return this;
}
this.counter++;
if (this.durableId == null && this.durableSupplier != null) {
try {
this.durableId = this.durableSupplier.get();
} catch (Throwable t) {
log.error("Failed to invoke durableSupplier, cause by:", t);
}
}
try {
this.noticeId = this.noticeSupplier.get();
state = 1;
} catch (Throwable t) {
state = -1;
log.error("Failed to invoke noticeSupplier: {}; cause by: " + this.noticeSupplier.toString(), t);
}
return this;
}
public boolean checkAck(long ackNoticeId) {
boolean flag = false;
if (this.noticeId == ackNoticeId) {
flag = true;
this.state = 2;
}
if (flag) {
this.doRemoveDurable();
}
return flag;
}
public boolean doRemoveDurable() {
log.info("Removing NoticeBroadcaster is stating, noticeId:{}, durableId: {}"
, this.noticeId, this.durableId);
boolean flag = false;
if (this.removeFunction == null) {
log.warn("The remove-function hasn't been set.");
return false;
}
if (this.durableId == null) {
log.warn("The durableId hasn't been set.");
return false;
}
try {
if (!(flag = this.removeFunction.apply(this.durableId))) {
log.error("Removing NoticeBroadcaster was not complete, noticeId: {}, durableId: {}"
, this.noticeId, this.durableId);
}
} catch (Throwable t) {
log.error("Failed to remove NoticeBroadcaster, noticeId: "
+ this.noticeId + ", durableId: " + this.durableId + ". Cause by:", t);
}
return flag;
}
public void setDurableId(String durableId) {
if (HgAssert.isInvalid(durableId)) {
log.warn("Set an invalid durable-id to NoticeBroadcaster.");
}
this.durableId = durableId;
}
public long getNoticeId() {
return noticeId;
}
public int getState() {
return state;
}
public int getCounter() {
return counter;
}
public String getDurableId() {
return durableId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "NoticeBroadcaster{" +
"noticeId=" + noticeId +
", durableId='" + durableId + '\'' +
", state=" + state +
", counter=" + counter +
", timestamp=" + timestamp +
'}';
}
}
package org.apache.hugegraph.pd.notice;
import com.baidu.hugegraph.pd.common.HgAssert;
import lombok.extern.slf4j.Slf4j;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* @author lynn.bond@hotmail.com on 2022/2/10
*/
@Slf4j
public class NoticeBroadcaster {
private long noticeId;
private String durableId;
private Supplier<Long> noticeSupplier;
private Supplier<String> durableSupplier;
private Function<String, Boolean> removeFunction;
private int state; //0=ready; 1=notified; 2=done ack; -1=error
private int counter;
private long timestamp;
public static NoticeBroadcaster of(Supplier<Long> noticeSupplier) {
HgAssert.isArgumentNotNull(noticeSupplier, "noticeSupplier");
return new NoticeBroadcaster(noticeSupplier);
}
private NoticeBroadcaster(Supplier<Long> noticeSupplier) {
this.noticeSupplier = noticeSupplier;
this.timestamp = System.currentTimeMillis();
}
public NoticeBroadcaster setDurableSupplier(Supplier<String> durableSupplier) {
this.durableSupplier = durableSupplier;
return this;
}
public NoticeBroadcaster setRemoveFunction(Function<String, Boolean> removeFunction) {
this.removeFunction = removeFunction;
return this;
}
public NoticeBroadcaster notifying() {
if (this.state >= 2) {
log.warn("Aborted notifying as ack has done. notice: {}", this);
return this;
}
this.counter++;
if (this.durableId == null && this.durableSupplier != null) {
try {
this.durableId = this.durableSupplier.get();
} catch (Throwable t) {
log.error("Failed to invoke durableSupplier, cause by:", t);
}
}
try {
this.noticeId = this.noticeSupplier.get();
state = 1;
} catch (Throwable t) {
state = -1;
log.error("Failed to invoke noticeSupplier: {}; cause by: " + this.noticeSupplier.toString(), t);
}
return this;
}
public boolean checkAck(long ackNoticeId) {
boolean flag = false;
if (this.noticeId == ackNoticeId) {
flag = true;
this.state = 2;
}
if (flag) {
this.doRemoveDurable();
}
return flag;
}
public boolean doRemoveDurable() {
log.info("Removing NoticeBroadcaster is stating, noticeId:{}, durableId: {}"
, this.noticeId, this.durableId);
boolean flag = false;
if (this.removeFunction == null) {
log.warn("The remove-function hasn't been set.");
return false;
}
if (this.durableId == null) {
log.warn("The durableId hasn't been set.");
return false;
}
try {
if (!(flag = this.removeFunction.apply(this.durableId))) {
log.error("Removing NoticeBroadcaster was not complete, noticeId: {}, durableId: {}"
, this.noticeId, this.durableId);
}
} catch (Throwable t) {
log.error("Failed to remove NoticeBroadcaster, noticeId: "
+ this.noticeId + ", durableId: " + this.durableId + ". Cause by:", t);
}
return flag;
}
public void setDurableId(String durableId) {
if (HgAssert.isInvalid(durableId)) {
log.warn("Set an invalid durable-id to NoticeBroadcaster.");
}
this.durableId = durableId;
}
public long getNoticeId() {
return noticeId;
}
public int getState() {
return state;
}
public int getCounter() {
return counter;
}
public String getDurableId() {
return durableId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "NoticeBroadcaster{" +
"noticeId=" + noticeId +
", durableId='" + durableId + '\'' +
", state=" + state +
", counter=" + counter +
", timestamp=" + timestamp +
'}';
}
}

View File

@ -1,72 +1,72 @@
package org.apache.hugegraph.pd.rest;
import org.apache.hugegraph.pd.model.PromTargetsModel;
import org.apache.hugegraph.pd.service.PromTargetsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* @author lynn.bond@hotmail.com on 2022/2/14
*/
@RestController
@Slf4j
@RequestMapping("/v1/prom")
public class PromTargetsAPI {
@Autowired
private PromTargetsService service;
@GetMapping(value = "/targets/{appName}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PromTargetsModel>> getPromTargets(@PathVariable(value = "appName", required = true) String appName) {
return ResponseEntity.of(Optional.ofNullable(this.service.getTargets(appName)));
}
@GetMapping(value = "/targets-all", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PromTargetsModel>> getPromAllTargets() {
return ResponseEntity.of(Optional.ofNullable(this.service.getAllTargets()));
}
@GetMapping(value = "/demo/targets/{appName}", produces = MediaType.APPLICATION_JSON_VALUE)
public List<PromTargetsModel> getDemoTargets(@PathVariable(value = "appName", required = true) String targetType) {
PromTargetsModel model =null;
switch (targetType) {
case "node":
model=PromTargetsModel.of()
.addTarget("10.14.139.26:8100")
.addTarget("10.14.139.27:8100")
.addTarget("10.14.139.28:8100")
.setMetricsPath("/metrics")
.setScheme("http");
break;
case "store":
model=PromTargetsModel.of()
.addTarget("172.20.94.98:8521")
.addTarget("172.20.94.98:8522")
.addTarget("172.20.94.98:8523")
.setMetricsPath("/actuator/prometheus")
.setScheme("http");
break;
case "pd":
model=PromTargetsModel.of()
.addTarget("172.20.94.98:8620")
.setMetricsPath("/actuator/prometheus");
break;
default:
}
return Collections.singletonList(model);
}
}
package org.apache.hugegraph.pd.rest;
import org.apache.hugegraph.pd.model.PromTargetsModel;
import org.apache.hugegraph.pd.service.PromTargetsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* @author lynn.bond@hotmail.com on 2022/2/14
*/
@RestController
@Slf4j
@RequestMapping("/v1/prom")
public class PromTargetsAPI {
@Autowired
private PromTargetsService service;
@GetMapping(value = "/targets/{appName}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PromTargetsModel>> getPromTargets(@PathVariable(value = "appName", required = true) String appName) {
return ResponseEntity.of(Optional.ofNullable(this.service.getTargets(appName)));
}
@GetMapping(value = "/targets-all", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PromTargetsModel>> getPromAllTargets() {
return ResponseEntity.of(Optional.ofNullable(this.service.getAllTargets()));
}
@GetMapping(value = "/demo/targets/{appName}", produces = MediaType.APPLICATION_JSON_VALUE)
public List<PromTargetsModel> getDemoTargets(@PathVariable(value = "appName", required = true) String targetType) {
PromTargetsModel model =null;
switch (targetType) {
case "node":
model=PromTargetsModel.of()
.addTarget("10.14.139.26:8100")
.addTarget("10.14.139.27:8100")
.addTarget("10.14.139.28:8100")
.setMetricsPath("/metrics")
.setScheme("http");
break;
case "store":
model=PromTargetsModel.of()
.addTarget("172.20.94.98:8521")
.addTarget("172.20.94.98:8522")
.addTarget("172.20.94.98:8523")
.setMetricsPath("/actuator/prometheus")
.setScheme("http");
break;
case "pd":
model=PromTargetsModel.of()
.addTarget("172.20.94.98:8620")
.setMetricsPath("/actuator/prometheus");
break;
default:
}
return Collections.singletonList(model);
}
}

View File

@ -1,140 +1,140 @@
package org.apache.hugegraph.pd.rest;
import com.baidu.hugegraph.pd.RegistryService;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.config.PDConfig;
import com.baidu.hugegraph.pd.grpc.Metapb;
import com.baidu.hugegraph.pd.grpc.discovery.Query;
import com.baidu.hugegraph.pd.grpc.pulse.ChangeShard;
import com.baidu.hugegraph.pd.grpc.pulse.PartitionHeartbeatResponse;
import com.baidu.hugegraph.pd.meta.MetadataFactory;
import com.baidu.hugegraph.pd.meta.QueueStore;
import org.apache.hugegraph.pd.pulse.PDPulseSubject;
import org.apache.hugegraph.pd.watch.PDWatchSubject;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Parser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author lynn.bond@hotmail.com on 2022/2/9
*/
@RestController
@Slf4j
@RequestMapping("/test")
public class TestAPI {
@Autowired
private PDConfig pdConfig;
@GetMapping(value = "/discovery/{appName}", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String discovery(@PathVariable(value = "appName", required = true)String appName){
RegistryService register =new RegistryService(pdConfig);
// Query query=Query.newBuilder().setAppName("hugegraph").build();
AtomicLong label = new AtomicLong();
HashMap<String, String> labels = new HashMap<>();
String labelValue = String.valueOf(label.incrementAndGet());
//labels.put("address",labelValue);
Query query = Query.newBuilder().build();
// Query query = Query.newBuilder().setAppName("hugegraph").set.build();
return register.getNodes(query).toString();
}
@GetMapping(value = "/pulse", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String notifyClient() {
PDPulseSubject.notifyClient(
PartitionHeartbeatResponse.newBuilder()
.setPartition(Metapb.Partition.newBuilder()
.setId(8)
.setGraphName("graphName8"))
.setChangeShard(
ChangeShard.newBuilder()
.setChangeTypeValue(8)
.addShard(Metapb.Shard.newBuilder()
.setRoleValue(8)
.setStoreId(8)
)
)
);
return "partition";
}
@GetMapping(value = "/partition", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String noticePartition() {
PDWatchSubject.notifyPartitionChange(PDWatchSubject.ChangeType.ALTER, "graph-test", 99);
return "partition";
}
@PutMapping(value = "/queue", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String testPutQueue() {
this.putQueue();
return "queue";
}
public void putQueue(){
PartitionHeartbeatResponse response=PartitionHeartbeatResponse.newBuilder()
.setPartition(Metapb.Partition.newBuilder()
.setId(9)
.setGraphName("graphName"))
.setChangeShard(
ChangeShard.newBuilder()
.setChangeTypeValue(9)
.addShard(Metapb.Shard.newBuilder()
.setRoleValue(9)
.setStoreId(9)
)
).build();
Metapb.QueueItem.Builder builder=Metapb.QueueItem.newBuilder()
.setItemId("item-id")
.setItemClass("item-class")
.setItemContent(response.toByteString());
QueueStore store= MetadataFactory.newQueueStore(pdConfig);
try {
store.addItem(builder.setItemId("item-id-1").build());
store.addItem(builder.setItemId("item-id-2").build());
store.addItem(builder.setItemId("item-id-3").build());
} catch (PDException e) {
e.printStackTrace();
}
List<Metapb.QueueItem> queue=null;
try {
queue=store.getQueue();
} catch (PDException e) {
e.printStackTrace();
}
Parser<PartitionHeartbeatResponse> parser= PartitionHeartbeatResponse.parser();
queue.stream().forEach(e->{
PartitionHeartbeatResponse buf=null;
try {
buf=parser.parseFrom(e.getItemContent());
} catch (InvalidProtocolBufferException ex) {
ex.printStackTrace();
}
PDPulseSubject.notifyClient( PartitionHeartbeatResponse.newBuilder(buf));
});
}
}
package org.apache.hugegraph.pd.rest;
import com.baidu.hugegraph.pd.RegistryService;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.config.PDConfig;
import com.baidu.hugegraph.pd.grpc.Metapb;
import com.baidu.hugegraph.pd.grpc.discovery.Query;
import com.baidu.hugegraph.pd.grpc.pulse.ChangeShard;
import com.baidu.hugegraph.pd.grpc.pulse.PartitionHeartbeatResponse;
import com.baidu.hugegraph.pd.meta.MetadataFactory;
import com.baidu.hugegraph.pd.meta.QueueStore;
import org.apache.hugegraph.pd.pulse.PDPulseSubject;
import org.apache.hugegraph.pd.watch.PDWatchSubject;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Parser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author lynn.bond@hotmail.com on 2022/2/9
*/
@RestController
@Slf4j
@RequestMapping("/test")
public class TestAPI {
@Autowired
private PDConfig pdConfig;
@GetMapping(value = "/discovery/{appName}", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String discovery(@PathVariable(value = "appName", required = true)String appName){
RegistryService register =new RegistryService(pdConfig);
// Query query=Query.newBuilder().setAppName("hugegraph").build();
AtomicLong label = new AtomicLong();
HashMap<String, String> labels = new HashMap<>();
String labelValue = String.valueOf(label.incrementAndGet());
//labels.put("address",labelValue);
Query query = Query.newBuilder().build();
// Query query = Query.newBuilder().setAppName("hugegraph").set.build();
return register.getNodes(query).toString();
}
@GetMapping(value = "/pulse", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String notifyClient() {
PDPulseSubject.notifyClient(
PartitionHeartbeatResponse.newBuilder()
.setPartition(Metapb.Partition.newBuilder()
.setId(8)
.setGraphName("graphName8"))
.setChangeShard(
ChangeShard.newBuilder()
.setChangeTypeValue(8)
.addShard(Metapb.Shard.newBuilder()
.setRoleValue(8)
.setStoreId(8)
)
)
);
return "partition";
}
@GetMapping(value = "/partition", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String noticePartition() {
PDWatchSubject.notifyPartitionChange(PDWatchSubject.ChangeType.ALTER, "graph-test", 99);
return "partition";
}
@PutMapping(value = "/queue", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String testPutQueue() {
this.putQueue();
return "queue";
}
public void putQueue(){
PartitionHeartbeatResponse response=PartitionHeartbeatResponse.newBuilder()
.setPartition(Metapb.Partition.newBuilder()
.setId(9)
.setGraphName("graphName"))
.setChangeShard(
ChangeShard.newBuilder()
.setChangeTypeValue(9)
.addShard(Metapb.Shard.newBuilder()
.setRoleValue(9)
.setStoreId(9)
)
).build();
Metapb.QueueItem.Builder builder=Metapb.QueueItem.newBuilder()
.setItemId("item-id")
.setItemClass("item-class")
.setItemContent(response.toByteString());
QueueStore store= MetadataFactory.newQueueStore(pdConfig);
try {
store.addItem(builder.setItemId("item-id-1").build());
store.addItem(builder.setItemId("item-id-2").build());
store.addItem(builder.setItemId("item-id-3").build());
} catch (PDException e) {
e.printStackTrace();
}
List<Metapb.QueueItem> queue=null;
try {
queue=store.getQueue();
} catch (PDException e) {
e.printStackTrace();
}
Parser<PartitionHeartbeatResponse> parser= PartitionHeartbeatResponse.parser();
queue.stream().forEach(e->{
PartitionHeartbeatResponse buf=null;
try {
buf=parser.parseFrom(e.getItemContent());
} catch (InvalidProtocolBufferException ex) {
ex.printStackTrace();
}
PDPulseSubject.notifyClient( PartitionHeartbeatResponse.newBuilder(buf));
});
}
}

View File

@ -1,234 +1,234 @@
package org.apache.hugegraph.pd.service;
import com.baidu.hugegraph.pd.RegistryService;
import com.baidu.hugegraph.pd.common.HgAssert;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.config.PDConfig;
import com.baidu.hugegraph.pd.grpc.Metapb;
import com.baidu.hugegraph.pd.grpc.Pdpb;
import com.baidu.hugegraph.pd.grpc.discovery.NodeInfo;
import com.baidu.hugegraph.pd.grpc.discovery.NodeInfos;
import com.baidu.hugegraph.pd.grpc.discovery.Query;
import org.apache.hugegraph.pd.util.HgMapCache;
import org.apache.hugegraph.pd.model.PromTargetsModel;
import org.apache.hugegraph.pd.rest.MemberAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* @author lynn.bond@hotmail.com on 2022/2/24
*/
@Service
@Slf4j
public class PromTargetsService {
@Autowired
private PDConfig pdConfig;
@Autowired
private PDService pdService;
private RegistryService register;
private final PromTargetsModel pdModel = PromTargetsModel.of()
.addLabel("__app_name", "pd")
.setScheme("http")
.setMetricsPath("/actuator/prometheus");
private final PromTargetsModel storeModel = PromTargetsModel.of()
.addLabel("__app_name", "store")
.setScheme("http")
.setMetricsPath("/actuator/prometheus");
private HgMapCache<String, Set<String>> targetsCache = HgMapCache.expiredOf(24 * 60 * 60 * 1000);// expired after 24H.
private RegistryService getRegister() {
if (this.register == null) {
this.register = new RegistryService(this.pdConfig);
}
return this.register;
}
public List<PromTargetsModel> getAllTargets() {
List<PromTargetsModel> res = new LinkedList<>();
List<PromTargetsModel> buf = this.toModels(this.getRegister().getNodes(Query.newBuilder().build()));
if (buf != null) {
res.addAll(buf);
}
res.add(getPdTargets());
res.add(getStoreTargets());
return res;
}
/**
* @param appName
* @return null if it's not existing
*/
public List<PromTargetsModel> getTargets(String appName) {
HgAssert.isArgumentNotNull(appName, "appName");
switch (appName) {
case "pd":
return Collections.singletonList(this.getPdTargets());
case "store":
return Collections.singletonList(this.getStoreTargets());
default:
return this.toModels(this.getRegister().getNodes(Query.newBuilder().setAppName(appName).build()));
}
}
private PromTargetsModel getPdTargets() {
return setTargets(pdModel, () -> this.mergeCache("pd", getPdAddresses()));
}
private PromTargetsModel getStoreTargets() {
return setTargets(storeModel, () -> this.mergeCache("store", getStoreAddresses()));
}
private PromTargetsModel setTargets(PromTargetsModel model, Supplier<Set<String>> supplier) {
return model.setTargets(supplier.get()).setClusterId(String.valueOf(pdConfig.getClusterId()));
}
/* to prevent the failure of connection between pd and store or pd and pd.*/
//TODO: To add a schedule task to refresh targets, not to retrieve in every time.
private Set<String> mergeCache(String key, Set<String> set) {
Set<String> buf = this.targetsCache.get(key);
if (buf == null) {
buf = new HashSet<>();
this.targetsCache.put(key, buf);
}
if (set != null) {
buf.addAll(set);
}
return buf;
}
private List<PromTargetsModel> toModels(NodeInfos info) {
if (info == null) {
return null;
}
List<NodeInfo> nodes = info.getInfoList();
if (nodes == null || nodes.isEmpty()) {
return null;
}
List<PromTargetsModel> res =
nodes.stream().map(e -> {
Map<String, String> labels = e.getLabelsMap();
String target = labels.get("target");
if (HgAssert.isInvalid(target)) return null;
PromTargetsModel model = PromTargetsModel.of();
model.addTarget(target);
model.addLabel("__app_name", e.getAppName());
labels.forEach((k, v) -> {
k = k.trim();
switch (k) {
case "metrics":
model.setMetricsPath(v.trim());
break;
case "scheme":
model.setScheme(v.trim());
break;
default:
if (k.startsWith("__")) {
model.addLabel(k, v);
}
}
});
return model;
})
.filter(e -> e != null)
.collect(Collectors.toList());
if (res.isEmpty()) {
return null;
}
return res;
}
private Set<String> getPdAddresses() {
MemberAPI.CallStreamObserverWrap<Pdpb.GetMembersResponse> response = new MemberAPI.CallStreamObserverWrap<>();
pdService.getMembers(Pdpb.GetMembersRequest.newBuilder().build(), response);
List<Metapb.Member> members = null;
try {
members = response.get().get(0).getMembersList();
} catch (Throwable e) {
log.error("Failed to get all pd members.", e);
}
Set<String> res = new HashSet<>();
if (members != null) {
members.stream().forEach(e -> res.add(e.getRestUrl()));
}
return res;
}
private Set<String> getStoreAddresses() {
Set<String> res = new HashSet<>();
List<Metapb.Store> stores = null;
try {
stores = pdService.getStoreNodeService().getStores();
} catch (PDException e) {
log.error("Failed to get all stores.", e);
}
if (stores != null) {
stores.stream().forEach(e -> {
String buf = this.getRestAddress(e);
if (buf != null) {
res.add(buf);
}
});
}
return res;
}
//TODO: optimized store registry data, to add host:port of REST server.
private String getRestAddress(Metapb.Store store) {
String address = store.getAddress();
if (address == null || address.isEmpty()) return null;
try {
Optional<String> port = store.getLabelsList().stream().map(
e -> {
if ("rest.port".equals(e.getKey())) {
return e.getValue();
}
return null;
}).filter(e -> e != null).findFirst();
if (port.isPresent()) {
address = address.substring(0, address.indexOf(':') + 1);
address = address + port.get();
}
} catch (Throwable t) {
log.error("Failed to extract the REST address of store, cause by:", t);
}
return address;
}
}
package org.apache.hugegraph.pd.service;
import com.baidu.hugegraph.pd.RegistryService;
import com.baidu.hugegraph.pd.common.HgAssert;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.config.PDConfig;
import com.baidu.hugegraph.pd.grpc.Metapb;
import com.baidu.hugegraph.pd.grpc.Pdpb;
import com.baidu.hugegraph.pd.grpc.discovery.NodeInfo;
import com.baidu.hugegraph.pd.grpc.discovery.NodeInfos;
import com.baidu.hugegraph.pd.grpc.discovery.Query;
import org.apache.hugegraph.pd.util.HgMapCache;
import org.apache.hugegraph.pd.model.PromTargetsModel;
import org.apache.hugegraph.pd.rest.MemberAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* @author lynn.bond@hotmail.com on 2022/2/24
*/
@Service
@Slf4j
public class PromTargetsService {
@Autowired
private PDConfig pdConfig;
@Autowired
private PDService pdService;
private RegistryService register;
private final PromTargetsModel pdModel = PromTargetsModel.of()
.addLabel("__app_name", "pd")
.setScheme("http")
.setMetricsPath("/actuator/prometheus");
private final PromTargetsModel storeModel = PromTargetsModel.of()
.addLabel("__app_name", "store")
.setScheme("http")
.setMetricsPath("/actuator/prometheus");
private HgMapCache<String, Set<String>> targetsCache = HgMapCache.expiredOf(24 * 60 * 60 * 1000);// expired after 24H.
private RegistryService getRegister() {
if (this.register == null) {
this.register = new RegistryService(this.pdConfig);
}
return this.register;
}
public List<PromTargetsModel> getAllTargets() {
List<PromTargetsModel> res = new LinkedList<>();
List<PromTargetsModel> buf = this.toModels(this.getRegister().getNodes(Query.newBuilder().build()));
if (buf != null) {
res.addAll(buf);
}
res.add(getPdTargets());
res.add(getStoreTargets());
return res;
}
/**
* @param appName
* @return null if it's not existing
*/
public List<PromTargetsModel> getTargets(String appName) {
HgAssert.isArgumentNotNull(appName, "appName");
switch (appName) {
case "pd":
return Collections.singletonList(this.getPdTargets());
case "store":
return Collections.singletonList(this.getStoreTargets());
default:
return this.toModels(this.getRegister().getNodes(Query.newBuilder().setAppName(appName).build()));
}
}
private PromTargetsModel getPdTargets() {
return setTargets(pdModel, () -> this.mergeCache("pd", getPdAddresses()));
}
private PromTargetsModel getStoreTargets() {
return setTargets(storeModel, () -> this.mergeCache("store", getStoreAddresses()));
}
private PromTargetsModel setTargets(PromTargetsModel model, Supplier<Set<String>> supplier) {
return model.setTargets(supplier.get()).setClusterId(String.valueOf(pdConfig.getClusterId()));
}
/* to prevent the failure of connection between pd and store or pd and pd.*/
//TODO: To add a schedule task to refresh targets, not to retrieve in every time.
private Set<String> mergeCache(String key, Set<String> set) {
Set<String> buf = this.targetsCache.get(key);
if (buf == null) {
buf = new HashSet<>();
this.targetsCache.put(key, buf);
}
if (set != null) {
buf.addAll(set);
}
return buf;
}
private List<PromTargetsModel> toModels(NodeInfos info) {
if (info == null) {
return null;
}
List<NodeInfo> nodes = info.getInfoList();
if (nodes == null || nodes.isEmpty()) {
return null;
}
List<PromTargetsModel> res =
nodes.stream().map(e -> {
Map<String, String> labels = e.getLabelsMap();
String target = labels.get("target");
if (HgAssert.isInvalid(target)) return null;
PromTargetsModel model = PromTargetsModel.of();
model.addTarget(target);
model.addLabel("__app_name", e.getAppName());
labels.forEach((k, v) -> {
k = k.trim();
switch (k) {
case "metrics":
model.setMetricsPath(v.trim());
break;
case "scheme":
model.setScheme(v.trim());
break;
default:
if (k.startsWith("__")) {
model.addLabel(k, v);
}
}
});
return model;
})
.filter(e -> e != null)
.collect(Collectors.toList());
if (res.isEmpty()) {
return null;
}
return res;
}
private Set<String> getPdAddresses() {
MemberAPI.CallStreamObserverWrap<Pdpb.GetMembersResponse> response = new MemberAPI.CallStreamObserverWrap<>();
pdService.getMembers(Pdpb.GetMembersRequest.newBuilder().build(), response);
List<Metapb.Member> members = null;
try {
members = response.get().get(0).getMembersList();
} catch (Throwable e) {
log.error("Failed to get all pd members.", e);
}
Set<String> res = new HashSet<>();
if (members != null) {
members.stream().forEach(e -> res.add(e.getRestUrl()));
}
return res;
}
private Set<String> getStoreAddresses() {
Set<String> res = new HashSet<>();
List<Metapb.Store> stores = null;
try {
stores = pdService.getStoreNodeService().getStores();
} catch (PDException e) {
log.error("Failed to get all stores.", e);
}
if (stores != null) {
stores.stream().forEach(e -> {
String buf = this.getRestAddress(e);
if (buf != null) {
res.add(buf);
}
});
}
return res;
}
//TODO: optimized store registry data, to add host:port of REST server.
private String getRestAddress(Metapb.Store store) {
String address = store.getAddress();
if (address == null || address.isEmpty()) return null;
try {
Optional<String> port = store.getLabelsList().stream().map(
e -> {
if ("rest.port".equals(e.getKey())) {
return e.getValue();
}
return null;
}).filter(e -> e != null).findFirst();
if (port.isPresent()) {
address = address.substring(0, address.indexOf(':') + 1);
address = address + port.get();
}
} catch (Throwable t) {
log.error("Failed to extract the REST address of store, cause by:", t);
}
return address;
}
}

View File

@ -1,82 +1,82 @@
package org.apache.hugegraph.pd.util;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
/**
* @param <K>
* @param <V>
* @author lynn.bond@hotmail.com on 2022/3/10
*/
public class HgMapCache<K, V> {
private Map<K, V> cache = new ConcurrentHashMap<K, V>();
private Supplier<Boolean> expiry;
public static HgMapCache expiredOf(long interval){
return new HgMapCache(new CycleIntervalPolicy(interval));
}
private HgMapCache(Supplier<Boolean> expiredPolicy) {
this.expiry = expiredPolicy;
}
private boolean isExpired() {
if (expiry != null && expiry.get()) {
cache.clear();
return true;
}
return false;
}
public void put(K key, V value) {
if (key == null || value == null) return;
this.cache.put(key, value);
}
public V get(K key) {
if (isExpired()) return null;
return this.cache.get(key);
}
public void removeAll() {
this.cache.clear();
}
public boolean remove(K key) {
if (key != null) {
this.cache.remove(key);
return true;
}
return false;
}
public Map<K, V> getAll() {
return this.cache;
}
private static class CycleIntervalPolicy implements Supplier<Boolean>{
private long expireTime=0;
private long interval=0;
public CycleIntervalPolicy(long interval){
this.interval=interval;
init();
}
private void init(){
expireTime=System.currentTimeMillis()+interval;
}
@Override
public Boolean get() {
if(System.currentTimeMillis()>expireTime){
init();
return true;
}
return false;
}
}
}
package org.apache.hugegraph.pd.util;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
/**
* @param <K>
* @param <V>
* @author lynn.bond@hotmail.com on 2022/3/10
*/
public class HgMapCache<K, V> {
private Map<K, V> cache = new ConcurrentHashMap<K, V>();
private Supplier<Boolean> expiry;
public static HgMapCache expiredOf(long interval){
return new HgMapCache(new CycleIntervalPolicy(interval));
}
private HgMapCache(Supplier<Boolean> expiredPolicy) {
this.expiry = expiredPolicy;
}
private boolean isExpired() {
if (expiry != null && expiry.get()) {
cache.clear();
return true;
}
return false;
}
public void put(K key, V value) {
if (key == null || value == null) return;
this.cache.put(key, value);
}
public V get(K key) {
if (isExpired()) return null;
return this.cache.get(key);
}
public void removeAll() {
this.cache.clear();
}
public boolean remove(K key) {
if (key != null) {
this.cache.remove(key);
return true;
}
return false;
}
public Map<K, V> getAll() {
return this.cache;
}
private static class CycleIntervalPolicy implements Supplier<Boolean>{
private long expireTime=0;
private long interval=0;
public CycleIntervalPolicy(long interval){
this.interval=interval;
init();
}
private void init(){
expireTime=System.currentTimeMillis()+interval;
}
@Override
public Boolean get() {
if(System.currentTimeMillis()>expireTime){
init();
return true;
}
return false;
}
}
}

View File

@ -1,32 +1,32 @@
package org.apache.hugegraph.pd.util;
import lombok.extern.slf4j.Slf4j;
/**
* @author lynn.bond@hotmail.com on 2022/2/8
*/
@Slf4j
public final class IdUtil {
private final static byte[] lock = new byte[0];
public static String createMillisStr(){
return String.valueOf(createMillisId());
}
/**
* Create millisecond style ID;
* @return
*/
public static Long createMillisId() {
synchronized (lock) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
log.error("Failed to sleep", e);
}
return System.currentTimeMillis();
}
}
}
package org.apache.hugegraph.pd.util;
import lombok.extern.slf4j.Slf4j;
/**
* @author lynn.bond@hotmail.com on 2022/2/8
*/
@Slf4j
public final class IdUtil {
private final static byte[] lock = new byte[0];
public static String createMillisStr(){
return String.valueOf(createMillisId());
}
/**
* Create millisecond style ID;
* @return
*/
public static Long createMillisId() {
synchronized (lock) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
log.error("Failed to sleep", e);
}
return System.currentTimeMillis();
}
}
}

View File

@ -1,113 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 修改这里更改本地缓存路径
<localRepository>
/path/to/cache/
</localRepository>
-->
<servers>
<server>
<id>star-local</id>
<username>superstar</username>
<password>Superstar12345</password>
</server>
<server>
<id>star-snapshot</id>
<username>superstar</username>
<password>Superstar12345</password>
</server>
</servers>
<profiles>
<profile>
<id>baidu</id>
<repositories>
<repository>
<id>baidu-nexus</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>baidu-nexus-snapshot</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 项目组自建仓库-->
<repository>
<id>star</id>
<url>http://10.14.139.8:8082/artifactory/star</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<!-- end -->
<repository>
<id>Baidu_Local</id>
<url>http://maven.baidu-int.com/nexus/content/repositories/Baidu_Local</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>Baidu_Local_Snapshots</id>
<url>http://maven.baidu-int.com/nexus/content/repositories/Baidu_Local_Snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories> <!-- plugin也需要从repository中获取 -->
<pluginRepository>
<id>baidu-nexus</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>baidu-nexus-snapshot</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>baidu</activeProfile> <!--别忘了激活配置 -->
</activeProfiles>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 修改这里更改本地缓存路径
<localRepository>
/path/to/cache/
</localRepository>
-->
<servers>
<server>
<id>star-local</id>
<username>superstar</username>
<password>Superstar12345</password>
</server>
<server>
<id>star-snapshot</id>
<username>superstar</username>
<password>Superstar12345</password>
</server>
</servers>
<profiles>
<profile>
<id>baidu</id>
<repositories>
<repository>
<id>baidu-nexus</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>baidu-nexus-snapshot</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 项目组自建仓库-->
<repository>
<id>star</id>
<url>http://10.14.139.8:8082/artifactory/star</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<!-- end -->
<repository>
<id>Baidu_Local</id>
<url>http://maven.baidu-int.com/nexus/content/repositories/Baidu_Local</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>Baidu_Local_Snapshots</id>
<url>http://maven.baidu-int.com/nexus/content/repositories/Baidu_Local_Snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories> <!-- plugin也需要从repository中获取 -->
<pluginRepository>
<id>baidu-nexus</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>baidu-nexus-snapshot</id>
<url>http://maven.baidu-int.com/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>baidu</activeProfile> <!--别忘了激活配置 -->
</activeProfiles>
</settings>