diff options
| author | Selvasundaram <selvam@gluster.com> | 2011-06-10 10:41:17 +0530 |
|---|---|---|
| committer | Selvasundaram <selvam@gluster.com> | 2011-06-14 17:44:29 +0530 |
| commit | 74e7c7673d80f1984bd62fd0268e1a0ba50b9203 (patch) | |
| tree | ab74f651bca172ac9793890d8a023aeed2dd4668 /src | |
| parent | a9a363955177bf1909b827a64faf9aa8a8a394bc (diff) | |
Tasks and MigrateDiskTask resources
Diffstat (limited to 'src')
8 files changed, 549 insertions, 0 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java index 428eb53f..4e8e8f33 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java @@ -38,6 +38,7 @@ public class RESTConstants { public static final String RESOURCE_RUNNING_TASKS = "runningtasks"; public static final String RESOURCE_ALERTS = "alerts"; public static final String RESOURCE_SERVERS = "servers"; + public static final String RESOURCE_TASKS = "tasks"; public static final String FORM_PARAM_CLUSTER_NAME = "clusterName"; public static final String FORM_PARAM_SERVER_NAME = "serverName"; @@ -56,6 +57,7 @@ public class RESTConstants { public static final String PATH_PARAM_VOLUME_NAME = "volumeName"; public static final String PATH_PARAM_CLUSTER_NAME = "clusterName"; public static final String PATH_PARAM_SERVER_NAME = "serverName"; + public static final String PATH_PARAM_TASK_ID = "taskId"; public static final String QUERY_PARAM_BRICK_NAME = "brickName"; public static final String QUERY_PARAM_DISKS = "disks"; @@ -68,4 +70,5 @@ public class RESTConstants { public static final String QUERY_PARAM_TO_TIMESTAMP = "toTimestamp"; public static final String QUERY_PARAM_DOWNLOAD = "download"; public static final String QUERY_PARAM_SERVER_NAME = "serverName"; + public static final String QUERY_PARAM_TASK_OPERATION = "taskOperation"; } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Task.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Task.java new file mode 100644 index 00000000..9268d060 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Task.java @@ -0,0 +1,66 @@ +/** + * Task.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.core.model; + +public abstract class Task { + public enum TASK_TYPE { + DISK_FORMAT, BRICK_MIGRATE, VOLUME_REBALANCE + } + + public String[] TASK_TYPE_STR = { "Format Disk", "Migrate Brick", "Volume Rebalance" }; + + private TaskInfo info; + + public Task(TASK_TYPE type, String reference, String description) { + info = new TaskInfo(); + info.setId(getTaskType(type) + "-" + reference); // construct id + info.setType(type); + info.setReference(reference); + info.setDescription(description); + } + public Task(TaskInfo info) { + setInfo(info); + } + + public String getTaskType(TASK_TYPE type) { + return TASK_TYPE_STR[type.ordinal()]; + } + + public abstract String getId(); + + public abstract TaskInfo resume(); + + public abstract TaskInfo stop(); + + public abstract TaskInfo pause(); + + public abstract TASK_TYPE getType(); + + public abstract TaskInfo getTaskInfo(); + + public TaskInfo getInfo() { + return info; + } + + public void setInfo(TaskInfo info) { + this.info = info; // TODO: review assigning reference and copy object + } +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskInfo.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskInfo.java new file mode 100644 index 00000000..d4549146 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskInfo.java @@ -0,0 +1,91 @@ +/** + * TaskInfo.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.core.model; + +import com.gluster.storage.management.core.model.Task.TASK_TYPE; + +public class TaskInfo extends Status { + private String id; + private TASK_TYPE type; + private String reference; + private String description; + private Boolean canPause; + private Boolean canStop; + private TaskStatus status; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public TASK_TYPE getType() { + return type; + } + + public void setType(TASK_TYPE type) { + this.type = type; + } + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public TaskStatus getStatus() { + return status; + } + + public void setStatus(TaskStatus status) { + this.status = status; + } + + public Boolean getCanPause() { + return canPause; + } + + public void setCanPause(Boolean canPause) { + this.canPause = canPause; + } + + public Boolean getCanStop() { + return canStop; + } + + public void setCanStop(Boolean canStop) { + this.canStop = canStop; + } + +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java new file mode 100644 index 00000000..46dc7b31 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/TaskStatus.java @@ -0,0 +1,60 @@ +/** + * TaskStatus.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.core.model; + +public class TaskStatus extends Status { + + private boolean isPercentageSupported; + private float percentCompleted; + private String description; + + public TaskStatus() { + + } + + public TaskStatus(Status status) { + super(status.getCode(), status.getMessage()); + } + + public boolean isPercentageSupported() { + return isPercentageSupported; + } + + public void setPercentageSupported(boolean isPercentageSupported) { + this.isPercentageSupported = isPercentageSupported; + } + + public float getPercentCompleted() { + return percentCompleted; + } + + public void setPercentCompleted(float percentCompleted) { + this.percentCompleted = percentCompleted; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskListResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskListResponse.java new file mode 100644 index 00000000..1bc9b5b5 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskListResponse.java @@ -0,0 +1,56 @@ +/** + * TaskListResponse.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.core.response; + +import java.util.ArrayList; +import java.util.List; + +import com.gluster.storage.management.core.model.Status; +import com.gluster.storage.management.core.model.TaskInfo; + +/** + * @author root + * + */ +public class TaskListResponse extends AbstractResponse { + private List<TaskInfo> taskList = new ArrayList<TaskInfo>(); + private Status status; + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + + public void setData(List<TaskInfo> taskList) { + this.taskList.clear(); + this.taskList.addAll(taskList); + } + + @Override + public Object getData() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskResponse.java new file mode 100755 index 00000000..a11c9903 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/response/TaskResponse.java @@ -0,0 +1,52 @@ +/** + * TaskInfoResponse.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.core.response; + +import javax.xml.bind.annotation.XmlRootElement; + +import com.gluster.storage.management.core.model.Status; +import com.gluster.storage.management.core.model.TaskInfo; + +@XmlRootElement(name = "response") +public class TaskResponse extends AbstractResponse { + private TaskInfo taskInfo; + private Status status; + + public TaskResponse() { + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public void setData(TaskInfo taskInfo) { + this.taskInfo = taskInfo; + } + + @Override + public TaskInfo getData() { + return taskInfo; + } +} diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/TaskResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/TaskResource.java new file mode 100644 index 00000000..c5540dff --- /dev/null +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/TaskResource.java @@ -0,0 +1,148 @@ +/** + * TaskResource.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.server.resources; + +import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_CLUSTER_NAME; +import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_TASK_ID; +import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_TASK_OPERATION; +import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS; +import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_TASKS; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; +import com.gluster.storage.management.core.model.Status; +import com.gluster.storage.management.core.model.Task; +import com.gluster.storage.management.core.model.Task.TASK_TYPE; +import com.gluster.storage.management.core.model.TaskInfo; +import com.gluster.storage.management.core.response.TaskListResponse; +import com.gluster.storage.management.core.response.TaskResponse; +import com.gluster.storage.management.server.runningtasks.managers.MigrateDiskManager; +import com.gluster.storage.management.server.tasks.MigrateDiskTask; +import com.sun.jersey.spi.resource.Singleton; + +@Path(RESOURCE_PATH_CLUSTERS + "/{" + PATH_PARAM_CLUSTER_NAME + "}/" + RESOURCE_TASKS) +@Singleton +public class TaskResource { + private Map<String, Task> tasks; + + private TaskResource() { + } + + public void addTask(Task task) { + tasks.put(task.getId(), task); + } + + public void removeTask(Task task) { + tasks.remove(task); + } + + public List<Task> getAllTasks() { + List<Task> allTasks = new ArrayList<Task>(); + for (Map.Entry<String, Task> entry : tasks.entrySet()) { + allTasks.add(entry.getValue()); + } + return allTasks; + } + + public Task getTask(String taskId) { + for (Map.Entry<String, Task> entry : tasks.entrySet()) { + if (entry.getValue().getId().equals(taskId)) { + return entry.getValue(); + } + } + return null; + } + + @GET + @Produces(MediaType.TEXT_XML) + public TaskListResponse getTasks() { + TaskListResponse taskListResponse = new TaskListResponse(); + List<TaskInfo> taskInfoList = new ArrayList<TaskInfo>(); + try { + for (Task task : getAllTasks()) { + taskInfoList.add(task.getTaskInfo()); + } + taskListResponse.setData(taskInfoList); + taskListResponse.setStatus(new Status(Status.STATUS_CODE_SUCCESS, "")); + } catch (GlusterRuntimeException e) { + taskListResponse.setStatus(new Status(e)); + } + return taskListResponse; + } + + @PUT + @Path("/{" + PATH_PARAM_TASK_ID + "}") + @Produces(MediaType.TEXT_XML) + public TaskResponse performTask(@PathParam(PATH_PARAM_TASK_ID) String taskId, + @QueryParam(QUERY_PARAM_TASK_OPERATION) String taskOperation) { + Task task = getTask(taskId); + TaskInfo taskInfo = null; + TaskResponse taskResponse = new TaskResponse(); + + try { + if (taskOperation.equals("resume")) { + taskInfo = task.resume(); + } + if (taskOperation.equals("pause")) { + taskInfo = task.pause(); + } + if (taskOperation.equals("stop")) { + taskInfo = task.stop(); + } + taskResponse.setData(taskInfo); + taskResponse.setStatus(new Status(Status.STATUS_CODE_SUCCESS, "")); + } catch (GlusterRuntimeException e) { + taskResponse.setStatus(new Status(e)); + } + return taskResponse; + } + + @DELETE + @Path("/{" + PATH_PARAM_TASK_ID + "}") + @Produces(MediaType.TEXT_XML) + public TaskResponse deleteTask(@PathParam(PATH_PARAM_TASK_ID) String taskId, + @QueryParam(QUERY_PARAM_TASK_OPERATION) String taskOperation) { + TaskResponse taskResponse = new TaskResponse(); + Task task = getTask(taskId); + if (task == null) { + taskResponse.setStatus( new Status(Status.STATUS_CODE_FAILURE, "No such task " + taskId + "is found ")); + } + if (taskOperation.equals("delete")) { + removeTask(task); + taskResponse.setStatus(new Status(Status.STATUS_CODE_SUCCESS, "Task [" + taskId + + "] removed successfully")); + } + return null; + } + +} diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateDiskTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateDiskTask.java new file mode 100644 index 00000000..97f3d2aa --- /dev/null +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateDiskTask.java @@ -0,0 +1,73 @@ +/** + * MigrateDiskTask.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero 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 Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + */ +package com.gluster.storage.management.server.tasks; + +import com.gluster.storage.management.core.model.Task; +import com.gluster.storage.management.core.model.TaskInfo; + +public class MigrateDiskTask extends Task { + + public MigrateDiskTask(TASK_TYPE type, String reference, String description ) { + super(type, reference, description ); + } + + public MigrateDiskTask(TaskInfo info) { + super(info); + } + + + @Override + public String getId() { + return getInfo().getId(); + } + + @Override + public TaskInfo resume() { + // To make a decision is the task has the ability to start the task + return null; + } + + + @Override + public TaskInfo stop() { + // To make a decision is the task has the ability to stop the task + return null; + } + + + @Override + public TaskInfo pause() { + // To make a decision is the task has the ability to pause the task + return null; + } + + + @Override + public TASK_TYPE getType() { + + return null; + } + + @Override + public TaskInfo getTaskInfo() { + return getInfo(); + } +} |
