summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.core/src/org/gluster/storage/management/core/model/Alert.java
blob: f55c9d35b39c1734810f4dbd499d73dbe0a3fea6 (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
/*******************************************************************************
 * Copyright (c) 2006-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 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 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.core.model;

import org.eclipse.osgi.internal.signedcontent.Base64;

@SuppressWarnings("restriction")
public class Alert extends Entity {

	public enum ALERT_TYPES {
		CPU_USAGE_ALERT, MEMORY_USAGE_ALERT, DISK_USAGE_ALERT, OFFLINE_VOLUME_BRICKS_ALERT, OFFLINE_SERVERS_ALERT, OFFLINE_VOLUME_ALERT
	};

	public static final String[] ALERT_TYPE_STR = { "High CPU Usage", "High Memory Usage", "Low Disk Space",
			"Offline Brick", "Offline Server", "Offline Volume" };

	//  protected String id;
	protected ALERT_TYPES type;
	protected String reference; // [for server- "Server", for Disk- "Server:disk", for volume- "Volume:Server:disk"]
	protected String message;

	public String getAlertType() {
		return ALERT_TYPE_STR[type.ordinal()];
	}

	public Alert() {
	}

	public Alert(ALERT_TYPES type, String reference, String Message) {
		setType(type);
		setReference(reference);
		setMessage(Message);
		setId(buildAlertId());
	}

	public String buildAlertId() {
		return Base64.encode((getAlertType() + "-" + getReference()).getBytes()).toString();
	}

	public String getId() {
		return getName();
	}

	public void setId(String id) {
		setName(id);
	}

	public ALERT_TYPES getType() {
		return type;
	}

	public void setType(ALERT_TYPES type) {
		this.type = type;
	}

	public String getReference() {
		return reference;
	}

	public void setReference(String reference) {
		this.reference = reference;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void copyFrom(Alert alert) {
		this.setId(alert.getId());
		this.setReference(alert.getReference());
		this.setType(alert.getType());
		this.setMessage(alert.getMessage());
	}
}