Search in sources :

Example 1 with ServerInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo in project elastic-job by dangdangdotcom.

the class ServerStatisticsAPIImpl method getJob.

private ServerInfo getJob(final String serverIp, final String jobName) {
    ServerInfo result = new ServerInfo();
    JobNodePath jobNodePath = new JobNodePath(jobName);
    result.setJobName(jobName);
    result.setIp(serverIp);
    result.setHostName(regCenter.get(jobNodePath.getServerNodePath(serverIp, "hostName")));
    result.setSharding(regCenter.get(jobNodePath.getServerNodePath(serverIp, "sharding")));
    String status = regCenter.get(jobNodePath.getServerNodePath(serverIp, "status"));
    boolean disabled = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "disabled"));
    boolean paused = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "paused"));
    boolean shutdown = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "shutdown"));
    result.setStatus(ServerInfo.ServerStatus.getServerStatus(status, disabled, paused, shutdown));
    return result;
}
Also used : ServerInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo) JobNodePath(com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)

Example 2 with ServerInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImplTest method assertGetServers.

@Test
public void assertGetServers() {
    when(regCenter.getChildrenKeys("/test_job/servers")).thenReturn(Arrays.asList("ip1", "ip2"));
    when(regCenter.get("/test_job/servers/ip1/hostName")).thenReturn("host1");
    when(regCenter.get("/test_job/servers/ip2/hostName")).thenReturn("host2");
    when(regCenter.get("/test_job/servers/ip1/sharding")).thenReturn("0,1");
    when(regCenter.get("/test_job/servers/ip2/sharding")).thenReturn("2,3");
    when(regCenter.get("/test_job/servers/ip1/status")).thenReturn("RUNNING");
    when(regCenter.get("/test_job/servers/ip2/status")).thenReturn("READY");
    int i = 0;
    for (ServerInfo each : jobStatisticsAPI.getServers("test_job")) {
        i++;
        assertThat(each.getJobName(), is("test_job"));
        assertThat(each.getIp(), is("ip" + i));
        assertThat(each.getHostName(), is("host" + i));
        switch(i) {
            case 1:
                assertThat(each.getStatus(), is(ServerInfo.ServerStatus.RUNNING));
                break;
            case 2:
                assertThat(each.getStatus(), is(ServerInfo.ServerStatus.READY));
                break;
            default:
                fail();
        }
    }
}
Also used : ServerInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo) Test(org.junit.Test)

Example 3 with ServerInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo in project elastic-job by dangdangdotcom.

the class ServerStatisticsAPIImplTest method assertGetJobs.

@Test
public void assertGetJobs() {
    when(regCenter.getChildrenKeys("/")).thenReturn(Arrays.asList("test_job1", "test_job2", "test_job3"));
    when(regCenter.isExisted("/test_job1/servers/localhost")).thenReturn(true);
    when(regCenter.isExisted("/test_job2/servers/localhost")).thenReturn(true);
    when(regCenter.isExisted("/test_job3/servers/localhost")).thenReturn(false);
    when(regCenter.get("/test_job1/servers/localhost/hostName")).thenReturn("localhost");
    when(regCenter.get("/test_job2/servers/localhost/hostName")).thenReturn("localhost");
    when(regCenter.get("/test_job1/servers/localhost/sharding")).thenReturn("0,1");
    when(regCenter.get("/test_job2/servers/localhost/sharding")).thenReturn("2");
    when(regCenter.get("/test_job1/servers/localhost/status")).thenReturn("RUNNING");
    when(regCenter.get("/test_job2/servers/localhost/status")).thenReturn("RUNNING");
    when(regCenter.isExisted("/test_job1/servers/localhost/disabled")).thenReturn(false);
    when(regCenter.isExisted("/test_job2/servers/localhost/disabled")).thenReturn(false);
    when(regCenter.isExisted("/test_job1/servers/localhost/paused")).thenReturn(false);
    when(regCenter.isExisted("/test_job2/servers/localhost/paused")).thenReturn(false);
    when(regCenter.isExisted("/test_job1/servers/localhost/shutdown")).thenReturn(false);
    when(regCenter.isExisted("/test_job2/servers/localhost/shutdown")).thenReturn(false);
    int i = 0;
    for (ServerInfo each : serverStatisticsAPI.getJobs("localhost")) {
        i++;
        assertThat(each.getJobName(), is("test_job" + i));
        assertThat(each.getIp(), is("localhost"));
        assertThat(each.getHostName(), is("localhost"));
        assertThat(each.getStatus(), is(ServerInfo.ServerStatus.RUNNING));
        switch(i) {
            case 1:
                assertThat(each.getSharding(), is("0,1"));
                break;
            case 2:
                assertThat(each.getSharding(), is("2"));
                break;
            default:
                fail();
        }
    }
}
Also used : ServerInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo) Test(org.junit.Test)

Example 4 with ServerInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImpl method getJobServer.

private ServerInfo getJobServer(final String jobName, final String serverIp) {
    ServerInfo result = new ServerInfo();
    JobNodePath jobNodePath = new JobNodePath(jobName);
    result.setJobName(jobName);
    result.setIp(serverIp);
    result.setHostName(regCenter.get(jobNodePath.getServerNodePath(serverIp, "hostName")));
    result.setSharding(regCenter.get(jobNodePath.getServerNodePath(serverIp, "sharding")));
    result.setStatus(getServerStatus(jobName, serverIp));
    return result;
}
Also used : ServerInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo) JobNodePath(com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)

Example 5 with ServerInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImpl method getServers.

@Override
public Collection<ServerInfo> getServers(final String jobName) {
    JobNodePath jobNodePath = new JobNodePath(jobName);
    List<String> serverIps = regCenter.getChildrenKeys(jobNodePath.getServerNodePath());
    Collection<ServerInfo> result = new ArrayList<>(serverIps.size());
    for (String each : serverIps) {
        result.add(getJobServer(jobName, each));
    }
    return result;
}
Also used : ServerInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo) ArrayList(java.util.ArrayList) JobNodePath(com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)

Aggregations

ServerInfo (com.dangdang.ddframe.job.lite.lifecycle.domain.ServerInfo)6 JobNodePath (com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2