summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.console/src/org/gluster/storage/management/console/dialogs/AddBrickWizard.java
blob: da40f1d9d94651472254770ff3e3a6700c8fefc0 (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
/**
 * AddDiskWizard.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 org.gluster.storage.management.console.dialogs;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.Wizard;
import org.gluster.storage.management.client.VolumesClient;
import org.gluster.storage.management.console.GlusterDataModelManager;
import org.gluster.storage.management.core.model.Brick;
import org.gluster.storage.management.core.model.Volume;
import org.gluster.storage.management.core.utils.StringUtil;


/**
 *
 */
public class AddBrickWizard extends Wizard {
	private AddBrickPage page;
	private Volume volume;

	public AddBrickWizard(Volume volume) {
		setWindowTitle("Gluster Management Console - Add Brick");
		setHelpAvailable(false); // TODO: Introduce wizard help
		this.volume = volume;
	}

	public void addPages() {
		page = new AddBrickPage(volume);
		addPage(page);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
	@Override
	public boolean performFinish() {
		Set<Brick> bricks = page.getChosenBricks(volume.getName());
		VolumesClient volumeClient = new VolumesClient();
		try {
			Set<String> brickList = getBrickList(bricks);
			
			volumeClient.addBricks(volume.getName(), brickList);

			// Update model with new bricks in the volume
			GlusterDataModelManager.getInstance().addBricks(volume, bricks);

			MessageDialog.openInformation(getShell(), "Add brick(s) to Volume", "Volume [" + volume.getName()
					+ "] is expanded with bricks [" + StringUtil.collectionToString(brickList, ", ") + "]");
			return true;
		} catch (Exception e) {
			MessageDialog.openError(getShell(), "Add brick(s) to Volume", e.getMessage());
			return false;
		}
	}

	private Set<String> getBrickList(Set<Brick> bricks) {
		Set<String> brickList = new HashSet<String>();
		for(Brick brick : bricks) {
			brickList.add(brick.getServerName() + ":" + brick.getBrickDirectory());
		}
		return brickList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.Wizard#canFinish()
	 */
	@Override
	public boolean canFinish() {
		return super.canFinish() && page.isPageComplete();
	}
}