summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.gateway/src/org/gluster/storage/management/gateway/tasks/Task.java
blob: 509e780325209abd562773174262fb35928cd209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*******************************************************************************
 * Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com>
 * This file is part of Gluster Management Gateway.
 *
 * Gluster Management Gateway is free software; you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * Gluster Management Gateway is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *******************************************************************************/
package org.gluster.storage.management.gateway.tasks;

import org.gluster.storage.management.core.model.GlusterServer;
import org.gluster.storage.management.core.model.TaskInfo;
import org.gluster.storage.management.core.model.TaskStatus;
import org.gluster.storage.management.core.model.TaskInfo.TASK_TYPE;
import org.gluster.storage.management.gateway.services.ClusterService;


public abstract class Task {
	public String[] TASK_TYPE_STR = { "Format Disk", "Migrate Brick", "Volume Rebalance" };
	
	protected TaskInfo taskInfo;	
	protected String clusterName;
	private ClusterService clusterService;
	
	public Task(ClusterService clusterService, String clusterName, TASK_TYPE type, String reference, String desc,
			boolean canPause, boolean canStop, boolean canCommit) {
		TaskInfo taskInfo = new TaskInfo();
		taskInfo.setType(type);
		taskInfo.setReference(reference);
		taskInfo.setDescription(desc);
		taskInfo.setPauseSupported(canPause);
		taskInfo.setStopSupported(canStop);
		taskInfo.setCommitSupported(canCommit);
		
		init(clusterService, clusterName, taskInfo);
		
	}
	
	public Task(ClusterService clusterService, String clusterName, TaskInfo taskInfo) {
		init(clusterService, clusterName, taskInfo);
	}
	
	private void init(ClusterService clusterService, String clusterName, TaskInfo taskInfo) {
		this.clusterService = clusterService;
		setClusterName(clusterName);
		setTaskInfo(taskInfo);
	}
	
	protected GlusterServer getOnlineServer() {
		return clusterService.getOnlineServer(clusterName);
	}
	
	protected GlusterServer getNewOnlineServer() {
		return clusterService.getNewOnlineServer(clusterName);
	}
	
	protected GlusterServer getNewOnlineServer(String exceptServerName) {
		return clusterService.getNewOnlineServer(clusterName, exceptServerName);
	}

	public String getTypeStr() {
		return TASK_TYPE_STR[taskInfo.getType().ordinal()];
	}
	
	public TASK_TYPE getType() {
		return getTaskInfo().getType();
	}
	
	public String getClusterName() {
		return clusterName;
	}
	
	public void setClusterName(String clusterName) {
		this.clusterName = clusterName;
	}
	
	public TaskInfo getTaskInfo() {
		return taskInfo;
	}
	
	public void setTaskInfo(TaskInfo info) {
		this.taskInfo = info;  
	}
	
	public abstract String getId();

	public abstract void start(); 
	
	public abstract void resume();

	public abstract void stop();

	public abstract void pause();
	
	public abstract void commit();

	/**
	 * This method should check current status of the task and update it's taskInfo accordingly
	 */
	public abstract TaskStatus checkStatus();
}