Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wenchaomeng committed Jan 16, 2017
2 parents ec7a175 + d2c314d commit 2db30f2
Show file tree
Hide file tree
Showing 104 changed files with 2,502 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.net.InetSocketAddress;
import java.util.List;

import com.ctrip.xpipe.api.codec.Codec;
import com.ctrip.xpipe.api.lifecycle.Ordered;
import com.ctrip.xpipe.utils.ServicesUtil;

Expand All @@ -23,6 +24,24 @@ public static class MigrationPublishResult {
private boolean Success;
private String Message;

private String startTime;
private String endTime;
private String publishAddress;
private String clusterName;
private String primaryDcName;
private List<InetSocketAddress> newMasters;

public MigrationPublishResult() {

}

public MigrationPublishResult(String publishAddress, String clusterName, String primaryDcName, List<InetSocketAddress> newMasters) {
this.publishAddress = publishAddress;
this.clusterName = clusterName;
this.primaryDcName = primaryDcName;
this.newMasters = newMasters;
}

public boolean isSuccess() {
return Success;
}
Expand All @@ -38,10 +57,58 @@ public String getMessage() {
public void setMessage(String message) {
Message = message;
}

public String getPublishAddress() {
return publishAddress;
}

public void setPublishAddress(String publishAddress) {
this.publishAddress = publishAddress;
}

public String getClusterName() {
return clusterName;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

public String getPrimaryDcName() {
return primaryDcName;
}

public void setPrimaryDcName(String primaryDcName) {
this.primaryDcName = primaryDcName;
}

public List<InetSocketAddress> getNewMasters() {
return newMasters;
}

public void setNewMasters(List<InetSocketAddress> newMasters) {
this.newMasters = newMasters;
}

public String getStartTime() {
return startTime;
}

public void setStartTime(String startTime) {
this.startTime = startTime;
}

public String getEndTime() {
return endTime;
}

public void setEndTime(String endTime) {
this.endTime = endTime;
}

@Override
public String toString() {
return String.format("Success:%s, Message:%s", Success, Message);
return Codec.DEFAULT.encode(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ctrip.xpipe.migration;

import java.text.SimpleDateFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,6 +16,8 @@ public abstract class AbstractMigrationPublishService implements MigrationPublis

protected Logger logger = LoggerFactory.getLogger(getClass());

protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ctrip.xpipe.migration;

import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
Expand All @@ -14,8 +16,12 @@ public class DefaultMigrationPublishService extends AbstractMigrationPublishServ
public MigrationPublishResult doMigrationPublish(String clusterName, String primaryDcName, List<InetSocketAddress> newMasters) {
logger.info("[doMigrationPublish]Cluster:{}, NewPrimaryDc:{}, Masters:{}", clusterName, primaryDcName,
newMasters);
MigrationPublishResult res = new MigrationPublishResult();
String startTime = sdf.format(new Date());
MigrationPublishResult res = new MigrationPublishResult("default-addr", clusterName, primaryDcName, newMasters);
String endTime = sdf.format(new Date());
res.setSuccess(true);res.setMessage("default-success");
res.setStartTime(startTime);
res.setEndTime(endTime);
return res;
}

Expand All @@ -24,8 +30,12 @@ public MigrationPublishResult doMigrationPublish(String clusterName, String shar
InetSocketAddress newMaster) {
logger.info("[doMigrationPublish]Cluster:{}, Shard:{}, NewPrimaryDc:{}, NewMaster:{}", clusterName, shardName,
primaryDcName, newMaster);
MigrationPublishResult res = new MigrationPublishResult();
String startTime = sdf.format(new Date());
MigrationPublishResult res = new MigrationPublishResult("default-addr", clusterName, primaryDcName, Arrays.asList(newMaster));
String endTime = sdf.format(new Date());
res.setSuccess(true);res.setMessage("default-success");
res.setStartTime(startTime);
res.setEndTime(endTime);
return res;
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/com/ctrip/xpipe/simple/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ public void testLog(){

Cat.getProducer().logError(new Exception());
}

@Test
public void testEnable() {
Cat.newTransaction("test", "test");
}

@Test
public void testDisable() {
System.setProperty("cat.client.enabled", "false");
Cat.newTransaction("test", "test");
}

}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<lettuce.version>4.3.0.Final</lettuce.version>
<pyrolite.version>4.9</pyrolite.version>
<hickwall.version>1.0</hickwall.version>
<hickwall.client.version>1.4</hickwall.client.version>
</properties>

<modules>
Expand Down Expand Up @@ -141,6 +142,11 @@
<artifactId>hickwall-protocol</artifactId>
<version>${hickwall.version}</version>
</dependency>
<dependency>
<groupId>com.ctrip.hickwall</groupId>
<artifactId>client</artifactId>
<version>${hickwall.client.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.ctrip.xpipe.redis.console.health.HealthChecker;

/**
* @author shyin
*
Expand All @@ -12,6 +14,7 @@
public class App {
public static void main(String[] args){
System.setProperty("spring.profiles.active", "production");
System.setProperty(HealthChecker.ENABLED, "true");
SpringApplication.run(App.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface ConsoleConfig extends CoreConfig {
Set<String> getConsoleUserAccessWhiteList();

int getRedisReplicationHealthCheckInterval();

String getHickwallAddress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DefaultConsoleConfig extends AbstractCoreConfig implements ConsoleC
public static final String KEY_METASERVERS = "metaservers";
public static final String KEY_USER_ACCESS_WHITE_LIST = "user.access.white.list";
public static final String KEY_REDIS_REPLICATION_HEALTH_CHECK_INTERVAL = "redis.replication.health.check.interval";
public static final String KEY_HICKWALL_ADDRESS = "console.hickwall.address";

@Override
public String getDatasource() {
Expand Down Expand Up @@ -55,5 +56,10 @@ public Set<String> getConsoleUserAccessWhiteList() {
public int getRedisReplicationHealthCheckInterval() {
return getIntProperty(KEY_REDIS_REPLICATION_HEALTH_CHECK_INTERVAL, 10000);
}

@Override
public String getHickwallAddress() {
return getProperty(KEY_HICKWALL_ADDRESS,"");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.ctrip.xpipe.redis.console.controller.consoleportal;

import java.util.Map;

import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.xpipe.metric.HostPort;
import com.ctrip.xpipe.redis.console.config.ConsoleConfig;
import com.ctrip.xpipe.redis.console.controller.AbstractConsoleController;
import com.ctrip.xpipe.redis.console.health.delay.DelayService;
import com.ctrip.xpipe.redis.console.health.ping.PingService;
import com.google.common.collect.ImmutableMap;

/**
* @author shyin
*
* Jan 5, 2017
*/
@RestController
@RequestMapping("console")
public class HealthCheckController extends AbstractConsoleController{

@Autowired
private PingService pingService;
@Autowired
private DelayService delayService;
@Autowired
private ConsoleConfig config;

@RequestMapping(value = "/redis/health/{redisIp}/{redisPort}", method = RequestMethod.GET)
public Map<String, Boolean> isRedisHealth(@PathVariable String redisIp, @PathVariable int redisPort) {
return ImmutableMap.of("isHealth", pingService.isRedisAlive(new HostPort(redisIp, redisPort)));
}

@RequestMapping(value = "/redis/delay/{redisIp}/{redisPort}", method = RequestMethod.GET)
public Map<String, Long> getReplDelayMillis(@PathVariable String redisIp, @PathVariable int redisPort) {
return ImmutableMap.of("delay", delayService.getDelay(new HostPort(redisIp, redisPort)));
}

@RequestMapping(value = "/redis/health/hickwall/{cluster}/{shard}/{redisIp}/{redisPort}", method = RequestMethod.GET)
public Map<String, String> getHickwallAddress(@PathVariable String cluster, @PathVariable String shard, @PathVariable String redisIp, @PathVariable int redisPort) {
String addr = config.getHickwallAddress();
if(Strings.isEmpty(addr)) {
return ImmutableMap.of("addr", "");
}
return ImmutableMap.of("addr", String.format("%s.%s.%s.%s.%s", addr, cluster, shard, redisIp, redisPort));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,28 @@ public List<MigrationClusterModel> getEventDetailsWithEventId(@PathVariable Long
}

@RequestMapping(value = "/migration/events/{eventId}/clusters/{clusterId}", method = RequestMethod.POST)
public void continueMigratiionCluster(@PathVariable Long eventId, @PathVariable Long clusterId) {
public void continueMigrationCluster(@PathVariable Long eventId, @PathVariable Long clusterId) {
migrationService.continueMigrationCluster(eventId, clusterId);
}

@RequestMapping(value = "/migration/events/{eventId}/clusters/{clusterId}/cancel", method = RequestMethod.POST)
public void cancelMigrationCluster(@PathVariable Long eventId, @PathVariable Long clusterId) {
migrationService.cancelMigrationCluster(eventId, clusterId);
}

@RequestMapping(value = "/migration/events/{eventId}/clusters/{clusterId}/rollback", method = RequestMethod.POST)
public void rollbackMigrationCluster(@PathVariable Long eventId, @PathVariable Long clusterId) {
migrationService.rollbackMigrationCluster(eventId, clusterId);
}

@RequestMapping(value = "/migration/events/{eventId}/clusters/{clusterId}/forcePublish", method = RequestMethod.POST)
public void forcePublishMigrationCluster(@PathVariable Long eventId, @PathVariable Long clusterId) {
migrationService.forcePublishMigrationCluster(eventId, clusterId);
}

@RequestMapping(value = "/migration/events/{eventId}/clusters/{clusterId}/forceEnd", method = RequestMethod.POST)
public void forceEndMigrationCluster(@PathVariable Long eventId, @PathVariable Long clusterId) {
migrationService.forceEndMigrationClsuter(eventId, clusterId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void updateRedises(@PathVariable String clusterName, @PathVariable String
}
} catch (Exception e) {
logger.error("[Update Redises][failed]{},{},{},{}",clusterName, dcName, shardName, shardModel);
throw e;
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.ctrip.xpipe.redis.console.controller.consoleportal;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.xpipe.redis.console.controller.AbstractConsoleController;
import com.ctrip.xpipe.redis.console.model.SetinelTbl;
import com.ctrip.xpipe.redis.console.service.SentinelService;

/**
* @author shyin
*
* Jan 4, 2017
*/
@RestController
@RequestMapping("/console")
public class SentinelController extends AbstractConsoleController{
@Autowired
private SentinelService sentinelService;

@RequestMapping(value="/{dcName}/sentinels", method = RequestMethod.GET)
public List<SetinelTbl> getSentinelsByDcName(@PathVariable String dcName) {
return sentinelService.findAllByDcName(dcName);
}

@RequestMapping(value="/sentinels/{sentinelId}", method = RequestMethod.GET)
public SetinelTbl findSentinel(@PathVariable long sentinelId){
return sentinelService.find(sentinelId);
}

@RequestMapping(value="/sentinels/shard/{shardId}", method = RequestMethod.GET)
public Map<Long,SetinelTbl> findSentinelByShard(@PathVariable long shardId) {
return sentinelService.findByShard(shardId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ShardController extends AbstractConsoleController{
private ShardService shardService;

@RequestMapping("/clusters/{clusterName}/dcs/{dcName}/shards")
public List<ShardModel> findShardMetas(@PathVariable String clusterName, @PathVariable String dcName){
public List<ShardModel> findShardModels(@PathVariable String clusterName, @PathVariable String dcName){
return new ArrayList<ShardModel>(shardModelService.getAllShardModel(dcName, clusterName));
}

Expand All @@ -39,14 +39,14 @@ public List<ShardTbl> findShards(@PathVariable String clusterName) {
}

@RequestMapping("/clusters/{clusterName}/dcs/{dcName}/shards/{shardName}")
public ShardModel findShardMeta(@PathVariable String clusterName, @PathVariable String dcName, @PathVariable String shardName) {
public ShardModel findShardModel(@PathVariable String clusterName, @PathVariable String dcName, @PathVariable String shardName) {
return shardModelService.getShardModel(dcName, clusterName, shardName);
}

@RequestMapping(value = "/clusters/{clusterName}/shards", method = RequestMethod.POST)
public ShardTbl createShard(@PathVariable String clusterName, @RequestBody ShardTbl shard) {
public ShardTbl createShard(@PathVariable String clusterName, @RequestBody ShardModel shard) {
logger.info("[Create Shard]{},{}",clusterName, shard);
return shardService.createShard(clusterName, shard);
return shardService.createShard(clusterName, shard.getShardTbl(), shard.getSentinels());
}

@RequestMapping(value = "/clusters/{clusterName}/shards/{shardName}", method = RequestMethod.DELETE)
Expand All @@ -55,5 +55,4 @@ public void deleteShard(@PathVariable String clusterName, @PathVariable String s
shardService.deleteShard(clusterName, shardName);
}


}
Loading

0 comments on commit 2db30f2

Please sign in to comment.