1 package org.apache.helix.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.helix.HelixProperty;
23 import org.apache.helix.ZNRecord;
24 import org.apache.log4j.Logger;
25
26
27
28
29
30 public class LiveInstance extends HelixProperty
31 {
32 public enum LiveInstanceProperty
33 {
34 SESSION_ID,
35 HELIX_VERSION,
36 LIVE_INSTANCE,
37 ZKPROPERTYTRANSFERURL
38 }
39
40 private static final Logger _logger = Logger.getLogger(LiveInstance.class.getName());
41
42 public LiveInstance(String id)
43 {
44 super(id);
45 }
46
47 public LiveInstance(ZNRecord record)
48 {
49 super(record);
50 }
51
52 public void setSessionId(String sessionId)
53 {
54 _record.setSimpleField(LiveInstanceProperty.SESSION_ID.toString(), sessionId);
55 }
56
57 public String getSessionId()
58 {
59 return _record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString());
60 }
61
62 public String getInstanceName()
63 {
64 return _record.getId();
65 }
66
67 public String getHelixVersion()
68 {
69 return _record.getSimpleField(LiveInstanceProperty.HELIX_VERSION.toString());
70 }
71
72 public void setHelixVersion(String helixVersion)
73 {
74 _record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), helixVersion);
75 }
76
77 public String getLiveInstance()
78 {
79 return _record.getSimpleField(LiveInstanceProperty.LIVE_INSTANCE.toString());
80 }
81
82 public void setLiveInstance(String leader)
83 {
84 _record.setSimpleField(LiveInstanceProperty.LIVE_INSTANCE.toString(), leader);
85 }
86
87 public long getModifiedTime()
88 {
89 return _record.getModifiedTime();
90 }
91
92 public String getWebserviceUrl()
93 {
94 return _record.getSimpleField(LiveInstanceProperty.ZKPROPERTYTRANSFERURL.toString());
95 }
96
97 public void setWebserviceUrl(String url)
98 {
99 _record.setSimpleField(LiveInstanceProperty.ZKPROPERTYTRANSFERURL.toString(), url);
100 }
101 @Override
102 public boolean isValid()
103 {
104 if(getSessionId() == null)
105 {
106 _logger.error("liveInstance does not have session id. id:" + _record.getId());
107 return false;
108 }
109 if(getHelixVersion() == null)
110 {
111 _logger.error("liveInstance does not have CLM verion. id:" + _record.getId());
112 return false;
113 }
114 return true;
115 }
116 }