View Javadoc

1   /*
2    * Copyright 2007-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwe.app.client.web.view;
18  
19  import org.gwe.persistence.model.AllocationInfo;
20  import org.gwe.persistence.model.HeadResourceInfo;
21  import org.gwe.persistence.model.JobExecutionInfo;
22  import org.gwe.persistence.model.JobInfo;
23  import org.gwe.persistence.model.OrderExecutionProfileInfo;
24  import org.gwe.persistence.model.OrderInfo;
25  import org.gwe.utils.web.HtmlPropsTable;
26  import org.gwe.utils.web.WebIcon;
27  
28  /**
29   * @author Marco Ruiz
30   * @since Dec 18, 2008
31   */
32  public abstract class HtmlModelPropsTable<MODEL_TYPE> extends HtmlPropsTable {
33  
34  	protected MODEL_TYPE modelObj;
35  
36  	public HtmlModelPropsTable(MODEL_TYPE model) {
37  		this.modelObj = model;
38  		if (model != null) populate();
39  	}
40  	
41  	protected abstract void populate();
42  	
43  	protected void populate(MODEL_TYPE model) {}
44  
45  	public String getHTML() {
46  		return isEmpty() ? null : super.getHTML();
47  	}
48  }
49  
50  class HtmlClusterPropsTable extends HtmlModelPropsTable<HeadResourceInfo> {
51  
52  	public HtmlClusterPropsTable(HeadResourceInfo daemonInfo) { super(daemonInfo); }
53  
54  	protected void populate() {
55          addPropertyRow("Name", modelObj.getName());
56          addPropertyRow("Host", modelObj.getHost());
57          addPropertyRow("Daemon Installation Path", modelObj.getInstallPath());
58          addPropertyRow("Daemon Database Path", modelObj.getDatabasePath());
59          addPropertyRow("Queue Size", modelObj.getQueueSize());
60          addPropertyRow("Compute Node Wait Connection Timeout", modelObj.getMaxWaitMins() + " minutes");
61          addPropertyRow("Compute Node Hijack Timeout", modelObj.getMaxHijackMins() + " minutes");
62          addPropertyRow("Compute Node Idle Timeout", modelObj.getMaxIdleMins() + " minutes");
63          addPropertyRow("Remote API Servers Registry", modelObj.getLocation());
64      }
65  }
66  
67  class HtmlOrderPropsTable extends HtmlModelPropsTable<OrderInfo> {
68  
69  	public HtmlOrderPropsTable(OrderInfo model) { super(model); }
70  
71  	public void populate() {
72  	    addPropertyRow("Order Id", modelObj.getId());
73          addPropertyRow("Submission Time", modelObj.getWhenCreated());
74          addPropertyRow("Completion Time", modelObj.getWhenCompleted());
75          addPropertyRow("Jobs Completed", modelObj.getCompletedJobsCount());
76          addPropertyRow("Jobs Count", modelObj.getTotalJobsCount());
77      }
78  
79  }
80  
81  class HtmlOrderProfilePropsTable extends HtmlModelPropsTable<OrderExecutionProfileInfo> {
82  
83  	public HtmlOrderProfilePropsTable(OrderExecutionProfileInfo model) { super(model); }
84  
85  	public void populate() {
86          addPropertyRow("Jobs launch mode", modelObj.getLaunchModeEnum());
87          addMaxTypeProperty("Max retries on failures", modelObj.getMaxRetries());
88          addMaxTypeProperty("Max run time per job (seconds)", modelObj.getMaxJobRunningTime());
89          addMaxTypeProperty("Max concurrent prepared jobs", modelObj.getMaxPreparedJobs());
90          addMaxTypeProperty("Max concurrent running jobs", modelObj.getMaxConcurrentRunningJobs());
91  	    addPropertyRow("VFS clean up mode", modelObj.getCleanUpModeEnum());
92  	    addMaxTypeProperty("VFS disk quota", modelObj.getDiskSpaceForVFS());
93          addPropertyRow("Use caching for VFS ?", new Boolean(modelObj.isUseVFSCache()).toString().toUpperCase());
94      }
95  	
96  	private void addMaxTypeProperty(String property, int value) {
97  		addPropertyRow(property, (value == -1) ? "NO LIMIT" : value + "");
98  	}
99  }
100 
101 class HtmlJobPropsTable extends HtmlModelPropsTable<JobInfo> {
102 
103 	public HtmlJobPropsTable(JobInfo job) { super(job); }
104 
105 	protected void populate() {
106 	    JobExecutionInfo exec = modelObj.getExecution();
107         addPropertyRow("Job Id", modelObj.getId());
108         addPropertyRow("Order Id", modelObj.getOrderId());
109         addPropertyRow("Job Number", modelObj.getJobNum());
110         addPropertyRow("Executions", trials(modelObj.getFailures() + 1));
111 	    addPropertyRow("Status", (exec == null) ? "WAITING" : exec.getStatus());
112     }
113 	
114 	private StringBuffer trials(int count) {
115 		StringBuffer result = new StringBuffer(count + " [ ");
116 		for (int idx = 1; idx < count + 1; idx++)
117 			result.append(getExecAnchor(idx) + " ");
118 		return result.append("]");
119 	}
120 
121 	private String getExecAnchor(int number) {
122 	    return "<a href=\"#" + number + "\">" + number + "</a>";
123     }
124 }
125 
126 class HtmlExecPropsTable extends HtmlModelPropsTable<JobExecutionInfo> {
127 
128 	public static WebIcon getStatusImage(JobExecutionInfo exec) {
129     	if (exec != null) {
130 	    	if (exec.getWhenFailed() != null) return WebIcon.STATUS_ERROR;
131 	    	if (exec.getWhenCompleted() != null) return WebIcon.STATUS_OK;
132     	}
133     	return WebIcon.STATUS_HELP;
134 	}
135 	
136 	public HtmlExecPropsTable(JobExecutionInfo exec) { super(exec); }
137 
138 	protected void populate() {
139 	    AllocationInfo alloc = modelObj.getAllocation();
140 		Integer allocId = (alloc != null) ? alloc.getId() : null;
141 	    addPropertyRow("Number",          modelObj.getExecutionNum());
142 		addPropertyRow("Allocation Id",   allocId);
143         addPropertyRow("Time Started",    modelObj.getWhenCreated());
144         addPropertyRow("Time Prepared",   modelObj.getWhenPrepared());
145         addPropertyRow("Time Dispatched", modelObj.getWhenDispatched());
146         addPropertyRow("Time Processed",  modelObj.getWhenProcessed());
147         addPropertyRow("Time Completed",  modelObj.getWhenCompleted());
148         addPropertyRow("Time Failed",     modelObj.getWhenFailed());
149     }
150 }