Ignore:
Timestamp:
07/19/13 10:20:00 (12 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/simulator/workload/WorkloadLoader.java

    r1131 r1144  
    11package simulator.workload; 
    22 
    3 import org.qcg.broker.schemas.jobdesc.Task; 
    4  
     3import java.io.BufferedReader; 
     4import java.io.FileReader; 
    55import java.io.IOException; 
    66import java.text.DateFormat; 
     
    5858        protected XsltTransformations xsltTransformation = null; 
    5959         
    60         protected Map<String, JobDescription> jobGridletsMap; 
    61         protected Map<String, JobDescription> jobProfilesMap; 
     60        protected Map<String, JobDescription> jobsMap; 
     61        protected Map<String, JobDescription> applicationProfilesMap; 
    6262 
    6363        public WorkloadLoader(XMLJobReader<org.qcg.broker.schemas.jobdesc.Job> xmlReader, WAReader<org.qcg.broker.schemas.jobdesc.Job> swfReader){ 
     
    6969                this.generatedJobsCnt = 0; 
    7070                this.generatedTasksCnt = 0; 
    71                 this.jobGridletsMap = new TreeMap<String, JobDescription>(); 
    72                 this.jobProfilesMap = new TreeMap<String, JobDescription>(); 
     71                this.jobsMap = new TreeMap<String, JobDescription>(); 
     72                this.applicationProfilesMap = new TreeMap<String, JobDescription>(); 
    7373                try { 
    7474                        this.xsltTransformation = new XsltTransformations(); 
     
    9797                } 
    9898                 
    99                 // needed for Gridlet class 
     99                // needed for Executable class 
    100100                 
    101101                String jobId = jobDescription.getJobId(); 
     
    107107                        String waTaskDesc[] = localWAParser.readTask(jobId, taskDesc.getTaskId()); 
    108108                         
    109                         try{ 
    110                                 Integer.parseInt(taskDesc.getTaskId()); 
    111                         } catch (NumberFormatException e){ 
    112                                 return jobDescription; 
    113                         } 
    114109                        if(waTaskDesc != null) { 
    115110                                 
     
    188183                        while((jobDesc = this.xmlJobReader.readRaw()) != null){ 
    189184                                jobDesc = this.xsltTransformation.extendJobDescription(jobDesc); 
    190                                 int prevJobCnt = generatedJobsCnt; 
    191                                 job = createJobDescription(jobDesc, puSpeed); 
    192                                 if(job != null && prevJobCnt != generatedJobsCnt) 
    193                                         this.jobGridletsMap.put(job.getJobId(), job); 
    194                                 else if (prevJobCnt == generatedJobsCnt){ 
    195                                         Task taskPattern = job.getDescription().getTask(0); 
    196                                         this.jobProfilesMap.put(taskPattern.getId(), job); 
    197                                 } 
    198                         } 
    199                 } else {                                                // use swf job reader. Job created by this reader does not require xslt transformation 
    200                         while((jobDesc = this.waReader.readRaw()) != null){ 
    201185                                job = createJobDescription(jobDesc, puSpeed); 
    202186                                if(job != null) 
    203                                         this.jobGridletsMap.put(job.getJobId(), job); 
    204                         } 
    205                 } 
    206                  
    207                 if(generatedJobsCnt == 0){ 
     187                                        this.jobsMap.put(job.getJobId(), job); 
     188                        } 
     189                } else {                                                // use swf job reader. Job created by this reader does not require xslt transformation 
     190                         
     191                        for(String key: waReader.getParser().getAppMapping().keySet()){ 
     192                                jobDesc = loadApplicationProfile(waReader.getParser().getAppMapping().get(key)); 
     193                                jobDesc = this.xsltTransformation.extendJobDescription(jobDesc); 
     194                                         
     195                                try { 
     196                                        job = this.xsltTransformation.splitJobToTasks(jobDesc); 
     197                                } catch (Exception e) { 
     198                                        throw new IOException(e.getMessage()); 
     199                                } 
     200                                 
     201                                this.applicationProfilesMap.put(key, job); 
     202                        } 
     203                         
    208204                        while((jobDesc = this.waReader.readRaw()) != null){ 
    209205                                QcgWAJobReader qcgReader = (QcgWAJobReader)waReader; 
    210                                 jobDesc = qcgReader.mergeSwfAndXmlProfile(jobProfilesMap, jobDesc); 
     206                                jobDesc = qcgReader.mergeSwfAndXmlProfile(applicationProfilesMap, jobDesc); 
    211207                                job = createJobDescription(jobDesc, puSpeed); 
    212208                                if(job != null) 
    213                                         this.jobGridletsMap.put(job.getJobId(), job); 
     209                                        this.jobsMap.put(job.getJobId(), job); 
    214210                        } 
    215211                } 
     
    268264        public List<JobDescription> getJobs(){ 
    269265                ArrayList<JobDescription> list =  
    270                         new ArrayList<JobDescription>(this.jobGridletsMap.values()); 
     266                        new ArrayList<JobDescription>(this.jobsMap.values()); 
    271267                return list; 
    272268        } 
     
    276272        } 
    277273 
    278         protected JobDescription createJobDescription(String jobDesc, long puSpeed, Map<String, JobDescription> jobProfilesMap) throws IOException{ 
    279                  
    280                 JobDescription jobDescription = null; 
    281                 try { 
    282                         jobDescription = this.xsltTransformation.splitJobToTasks(jobDesc); 
    283                 } catch (Exception e) { 
    284                         throw new IOException(e.getMessage()); 
    285                 } 
    286                  
    287                 // look for any  
    288                  
    289                 if(jobDescription.size() == 0){ 
    290                         if(log.isWarnEnabled()) 
    291                                 log.warn("Omitting tasks creation for job "+jobDescription.getDescription().getId()+". This job contains no tasks."); 
    292                         return null; 
    293                 } 
    294  
    295                 String jobId = jobDescription.getJobId(); 
    296                 int parserType = localWAParser.getType(); 
    297                  
    298                 for(int i = 0; i < jobDescription.size(); i++){ 
    299                         TaskDescription taskDesc = jobDescription.get(i); 
    300                          
    301                         String waTaskDesc[] = localWAParser.readTask(jobId, taskDesc.getTaskId()); 
    302                          
    303                         if(waTaskDesc != null) { 
    304                                  
    305                                 if(parserType == 0){ 
    306                                  
    307                                         taskDesc.setUserDn(waTaskDesc[SWFFields.DATA_USER_ID]); 
    308                                          
    309                                         long timeValue = Long.parseLong(waTaskDesc[SWFFields.DATA_SUBMIT_TIME]); 
    310                                         taskDesc.setSubmissionTime(timeValue); 
    311                                          
    312                                         long waitTime = Long.parseLong(waTaskDesc[SWFFields.DATA_WAIT_TIME]); 
    313                                         taskDesc.setWorkloadLogWaitTime(waitTime); 
    314                                          
    315                                         timeValue = Long.parseLong(waTaskDesc[SWFFields.DATA_RUN_TIME]); 
    316                                         if(timeValue <= 0) 
    317                                                 return null; 
    318                                          
    319                                         long allocProcesors = Long.parseLong(waTaskDesc[SWFFields.DATA_NUMBER_OF_ALLOCATED_PROCESSORS]); 
    320                                         if(allocProcesors <= 0) 
    321                                                 return null; 
    322                                          
    323                                         timeValue = timeValue * puSpeed * allocProcesors; 
    324                                         taskDesc.setTaskLength(timeValue); 
    325  
    326                                 } else if(parserType == 1){ 
    327                                  
    328                                         taskDesc.setUserDn(waTaskDesc[GWFFields.DATA_USER_ID]); 
    329                                          
    330                                         long timeValue = Long.parseLong(waTaskDesc[GWFFields.DATA_SUBMIT_TIME]); 
    331                                         taskDesc.setSubmissionTime(timeValue); 
    332                                          
    333                                         long waitTime = Long.parseLong(waTaskDesc[GWFFields.DATA_WAIT_TIME]); 
    334                                         taskDesc.setWorkloadLogWaitTime(waitTime); 
    335                                          
    336                                         timeValue = Long.parseLong(waTaskDesc[GWFFields.DATA_RUN_TIME]); 
    337                                         if(timeValue <= 0) 
    338                                                 return null; 
    339                                          
    340                                         long allocProcesors = Long.parseLong(waTaskDesc[GWFFields.DATA_NPROCS]); 
    341                                         if(allocProcesors <= 0) 
    342                                                 return null; 
    343                                          
    344                                         timeValue = timeValue * puSpeed * allocProcesors; 
    345                                         taskDesc.setTaskLength(timeValue); 
    346                                 } 
    347                         } 
    348                         /*JobDescription xmlJobDescription = jobProfilesMap.get(taskDesc.getDescription().getExecution().getExecutable().getApplication().getName()); 
    349                         if(xmlJobDescription != null){ 
    350                                 Task patternTask = xmlJobDescription.getDescription().getTask(0); 
    351                                 if(patternTask != null){ 
    352                                         ResourceConsumptionProfileType rcp = patternTask.getExecution().getResourceConsumptionProfile(); 
    353                                         taskDesc.getDescription().getExecution().setResourceConsumptionProfile(rcp); 
    354                                 } 
    355                         }*/ 
    356                         this.generatedTasksCnt++; 
    357                          
    358                 } 
    359                 this.generatedJobsCnt++; 
    360                  
    361                 return jobDescription; 
    362         } 
    363          
     274        public String loadApplicationProfile(String fileName) throws IOException{ 
     275                 
     276                BufferedReader reader = null; 
     277                StringBuffer buffer = new StringBuffer(); 
     278 
     279                try { 
     280                        reader = new BufferedReader(new FileReader(fileName)); 
     281                        String line = null; 
     282                         
     283                        while((line = reader.readLine()) != null){ 
     284                                buffer.append(line); 
     285                        } 
     286                         
     287                } finally{ 
     288                        reader.close(); 
     289                } 
     290                 
     291                return buffer.toString(); 
     292        } 
    364293} 
Note: See TracChangeset for help on using the changeset viewer.