View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21   
22  package org.miloss.fgsms.sla.rules;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.concurrent.atomic.AtomicReference;
27  import org.miloss.fgsms.common.Utility;
28  import org.miloss.fgsms.plugins.sla.SLARuleInterface;
29  import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
30  import org.miloss.fgsms.services.interfaces.common.NameValuePair;
31  import org.miloss.fgsms.services.interfaces.common.PolicyType;
32  import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
33  import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
34  import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
35  import org.miloss.fgsms.services.interfaces.policyconfiguration.MachinePolicy;
36  import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
37  import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
38  import org.miloss.fgsms.sla.NonTransactionalSLAProcessor;
39  
40  /**
41   *
42   * @author AO
43   */
44  public class HighDiskUsageOverTime  implements SLARuleInterface {
45  
46      @Override
47      public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
48          return false;
49      }
50  
51      @Override
52      public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
53          return false;
54      }
55  
56      @Override
57      public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
58          return false;
59      }
60  
61      @Override
62      public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
63          return false;
64      }
65  
66      @Override
67      public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
68          return false;
69      }
70  
71      @Override
72      public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
73          if (nullableFaultMsg == null) {
74              nullableFaultMsg = new AtomicReference<String>();
75          }
76          NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "value");
77          long rate = Long.parseLong(GetNameValuePairByName.getValue());
78          GetNameValuePairByName = Utility.getNameValuePairByName(params, "duration");
79          long duration = Long.parseLong(GetNameValuePairByName.getValue());
80          long faultrate = NonTransactionalSLAProcessor.GetDiskUsageOverTime(pol.getURL(),duration, pooled);
81          if (faultrate > rate) {
82              nullableFaultMsg.set("The measured Disk I/O rate" + faultrate + " is greater than " + rate + ", " + nullableFaultMsg.get());
83              return true;
84          }
85          return false;
86      }
87  
88      @Override
89      public String GetDisplayName() {
90          return "High Disk I/O Rates";
91      }
92  
93      @Override
94      public String GetHtmlFormattedHelp() {
95          return "This rule will trigger when the Disk I/O utilization rate is greater than the specified value for the specified duration."
96                  + "This rule is processed periodically as part of the Non-Transactional SLA Processor, who execution cycle is controled by the administrator. "
97                  + "This rule applies to Machine policies.<br><br>"
98                  + "Required parameters:"
99                  + "<ul>"
100                 + "<li>value - must be a positive integer. This is the threshold in KB</li>"
101                 + "<li>duration - must be a positive integer or long. This represents time in milliseconds for the duration. It must be one of the values from which"
102                 + "statistics are aggregated. By default, the following durations are calculated 5 minutes (300000ms), 15 minutes (900000ms), 1 hour (3600000ms),"
103                 + "and 24 hours (1440000ms). Administrators can add additional time periods for aggregation via General Settings."
104                 + "</il>"
105                 + "</ul>";
106     }
107 
108     @Override
109     public List<NameValuePair> GetRequiredParameters() {
110         ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
111         arrayList.add(Utility.newNameValuePair("value", null, false, false));
112         arrayList.add(Utility.newNameValuePair("duration", null, false, false));
113 
114         return arrayList;
115     }
116 
117     @Override
118     public List<NameValuePair> GetOptionalParameters() {
119         return new ArrayList<NameValuePair>();
120     }
121 
122     @Override
123     public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError,ServicePolicy policy) {
124         if (outError == null) {
125             outError = new AtomicReference<String>();
126         }
127         if (params == null || params.isEmpty()) {
128             outError.set("The parameter 'value' is required. " + outError.get());
129         }
130              if (!(policy instanceof MachinePolicy)) {
131             outError.set("This rule only applies to Machine Policies. " + outError.get());
132         }
133         boolean foundLogger = false;
134         boolean foundduration = false;
135         for (int i = 0; i < params.size(); i++) {
136             if (params.get(i).getName().equals("value")) {
137                 foundLogger = true;
138                 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
139                     outError.set("A value must be specified for the parameter 'value'. " + outError.get());
140                 }
141                 try {
142                     long x = Long.parseLong(params.get(i).getValue());
143                     if (x <= 0) {
144                         outError.set("The parameter 'value' must be greater than zero. " + outError.get());
145                     }
146                 } catch (Exception ex) {
147                     outError.set("Bad value for parameter 'value'. It must be an integer or long. Message:" + ex.getMessage() + ". " + outError.get());
148                 }
149             }
150             if (params.get(i).getName().equals("duration")) {
151                 foundduration = true;
152                 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
153                     outError.set("A value must be specified for the parameter 'duration'. " + outError.get());
154                 }
155                 try {
156                     long x = Long.parseLong(params.get(i).getValue());
157                     if (x <= 0) {
158                         outError.set("The parameter 'duration' must be greater than zero. " + outError.get());
159                     }
160                 } catch (Exception ex) {
161                     outError.set("Bad value for parameter 'duration'. It must be an integer or long. Message:" + ex.getMessage() + ". " + outError.get());
162                 }
163             }
164         }
165         if (!foundLogger) {
166             outError.set("The parameter 'value' is required. " + outError.get());
167         }
168           if (!foundduration) {
169             outError.set("The parameter 'duration' is required. " + outError.get());
170         }
171         if (Utility.stringIsNullOrEmpty(outError.get())) {
172             return true;
173         } else {
174             return false;
175         }
176     }
177     
178       @Override
179     public org.miloss.fgsms.plugins.sla.AlertType GetType() {
180        return org.miloss.fgsms.plugins.sla.AlertType.Performance;
181     }
182       
183       @Override
184     public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
185        NameValuePair mc = Utility.getNameValuePairByName(params, "value");
186         String item = UNDEFINED_VALUE;
187         if (mc != null) {
188             item = mc.getValue();
189             if (mc.isEncrypted() || mc.isEncryptOnSave()) {
190                 item = ENCRYPTED_MASK;
191             }
192         }
193         
194         NameValuePair mc2 = Utility.getNameValuePairByName(params, "duration");
195         String item2 = UNDEFINED_VALUE;
196         if (mc2 != null) {
197             item2 = mc2.getValue();
198             if (mc2.isEncrypted() || mc2.isEncryptOnSave()) {
199                 item2 = ENCRYPTED_MASK;
200             }
201         }
202         return Utility.encodeHTML(GetDisplayName() + " " + item + "/" + item2+"ms");
203     }
204       
205         @Override
206     public List<PolicyType> GetAppliesTo() {
207          List<PolicyType> x = new ArrayList<PolicyType>();
208          x.add(PolicyType.MACHINE);
209      
210          
211          return x;
212     }
213 }
214