Ignore:
Timestamp:
11/26/13 11:56:07 (11 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

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

    r1170 r1207  
    1717import javax.xml.xpath.XPathExpressionException; 
    1818 
     19import org.apache.commons.io.FilenameUtils; 
    1920import org.apache.commons.logging.Log; 
    2021import org.apache.commons.logging.LogFactory; 
     
    3233import simulator.workload.reader.archive.swf.SWFFields; 
    3334import simulator.workload.reader.xmlJob.XMLJobReader; 
     35import dcworms.schedframe.scheduling.utils.ApplicationProfileDescription; 
    3436import dcworms.schedframe.scheduling.utils.JobDescription; 
    3537import dcworms.schedframe.scheduling.utils.TaskDescription; 
     
    5658         
    5759        protected Map<String, JobDescription> jobsMap; 
    58         protected Map<String, JobDescription> applicationProfilesMap; 
    59  
    60         public WorkloadLoader(XMLJobReader<org.qcg.broker.schemas.jobdesc.Job> xmlReader, WAReader<org.qcg.broker.schemas.jobdesc.Job> swfReader){ 
     60         
     61        protected String appProfilesFolder; 
     62        protected Map<String, ApplicationProfileDescription> applicationProfiles; 
     63 
     64        public WorkloadLoader(XMLJobReader<org.qcg.broker.schemas.jobdesc.Job> xmlReader, WAReader<org.qcg.broker.schemas.jobdesc.Job> swfReader, String appProfilesFolder){ 
    6165                if(swfReader == null){ 
    6266                        throw new RuntimeException("Swf reader is required to build proper tasks."); 
     
    6771                this.generatedTasksCnt = 0; 
    6872                this.jobsMap = new TreeMap<String, JobDescription>(); 
    69                 this.applicationProfilesMap = new TreeMap<String, JobDescription>(); 
     73                this.appProfilesFolder = appProfilesFolder; 
     74                this.applicationProfiles = new TreeMap<String, ApplicationProfileDescription>(); 
    7075                try { 
    7176                        this.xsltTransformation = new XsltTransformations(); 
     
    187192 
    188193                // determine which reader should be used 
    189                 String jobDesc = null; 
    190                 JobDescription job = null; 
    191                          
     194                String xmlJob = null; 
     195                JobDescription jobDesc = null; 
     196                         
     197                for(String key: waReader.getParser().getAppProfilesLocation().keySet()){ 
     198                        String xmlApp = loadApplicationProfile(waReader.getParser().getAppProfilesLocation().get(key)); 
     199                        xmlApp = this.xsltTransformation.extendJobDescription(xmlApp); 
     200                        ApplicationProfileDescription app = this.xsltTransformation.getApplicationProfileDescription(xmlApp); 
     201                        this.applicationProfiles.put(key, app); 
     202                } 
     203                 
    192204                if(this.xmlJobReader != null){ // use xml job reader. Xml job require xslt transformation 
    193                         while((jobDesc = this.xmlJobReader.readRaw()) != null){ 
    194                                 jobDesc = this.xsltTransformation.extendJobDescription(jobDesc); 
    195                                 job = createJobDescription(jobDesc, puSpeed); 
    196                                 if(job != null) 
    197                                         this.jobsMap.put(job.getJobId(), job); 
     205                        while((xmlJob = this.xmlJobReader.readRaw()) != null){ 
     206                                xmlJob = this.xsltTransformation.extendJobDescription(xmlJob); 
     207                                jobDesc = createJobDescription(xmlJob, puSpeed); 
     208                                if(jobDesc != null) 
     209                                        this.jobsMap.put(jobDesc.getJobId(), jobDesc); 
    198210                        } 
    199211                } else {                                                // use swf job reader. Job created by this reader does not require xslt transformation 
    200212                         
    201                         for(String key: waReader.getParser().getAppMapping().keySet()){ 
    202                                 jobDesc = loadApplicationProfile(waReader.getParser().getAppMapping().get(key)); 
    203                                 jobDesc = this.xsltTransformation.extendJobDescription(jobDesc); 
    204                                          
    205                                 try { 
    206                                         job = this.xsltTransformation.splitJobToTasks(jobDesc); 
    207                                 } catch (Exception e) { 
    208                                         throw new IOException(e.getMessage()); 
    209                                 } 
    210                                  
    211                                 this.applicationProfilesMap.put(key, job); 
    212                         } 
    213                          
    214                         while((jobDesc = this.waReader.readRaw()) != null){ 
     213                        while((xmlJob = this.waReader.readRaw()) != null){ 
    215214                                QcgWAJobReader qcgReader = (QcgWAJobReader)waReader; 
    216                                 if(!applicationProfilesMap.isEmpty()) 
    217                                         jobDesc = qcgReader.mergeSwfAndXmlProfile(applicationProfilesMap, jobDesc); 
    218                                 job = createJobDescription(jobDesc, puSpeed); 
    219                                 /*if(job!= null && !applicationProfilesMap.isEmpty()){ 
    220                                         for(int i = 0; i < job.getDescription().getTaskCount(); i++){ 
    221                                                 try { 
    222                                                         JobDescription xmlJobDescription = applicationProfilesMap.get(job.getDescription().getTask(i).getExecution().getExecutable().getApplication().getAppProperty(0).getContent()); 
    223                                                         if(xmlJobDescription != null){ 
    224                                                                 for(int j = 0; j < xmlJobDescription.size(); j++){ 
    225                                                                         Task patternTask = xmlJobDescription.getDescription().getTask(j); 
    226                                                                         if(patternTask != null){ 
    227                                                                                 ResourceConsumptionProfileType rcp = patternTask.getExecution().getResourceConsumptionProfile(); 
    228                                                                                 job.getDescription().getTask(j).getExecution().setResourceConsumptionProfile(rcp); 
    229                                                                         } 
    230                                                                 } 
    231                                                         }        
    232                                                 } catch (Exception e){ 
    233                                                         continue; 
    234                                                 } 
    235                                         }                                        
    236                                 } 
    237                                 */ 
    238                                 if(job != null) 
    239                                         this.jobsMap.put(job.getJobId(), job); 
     215                                if(!applicationProfiles.isEmpty()) 
     216                                        xmlJob = qcgReader.mergeSwfAndAppProfile(applicationProfiles, xmlJob); 
     217                                jobDesc = createJobDescription(xmlJob, puSpeed); 
     218                                if(jobDesc != null) 
     219                                        this.jobsMap.put(jobDesc.getJobId(), jobDesc); 
    240220                        } 
    241221                } 
     
    302282        } 
    303283 
    304         public String loadApplicationProfile(String fileName) throws IOException{ 
     284        public String loadApplicationProfile(String pathToAppProfile) throws IOException{ 
    305285                 
    306286                BufferedReader reader = null; 
    307287                StringBuffer buffer = new StringBuffer(); 
    308288 
    309                 try { 
    310                         reader = new BufferedReader(new FileReader(fileName)); 
     289                String localPathToAppProfile; 
     290                 
     291                if(appProfilesFolder != null) { 
     292                        String folderName = FilenameUtils.getFullPath(appProfilesFolder); 
     293                        String fileName = FilenameUtils.getName(pathToAppProfile); 
     294                        localPathToAppProfile = folderName + fileName; 
     295                } else { 
     296                        localPathToAppProfile = pathToAppProfile; 
     297                } 
     298                try { 
     299                        reader = new BufferedReader(new FileReader(localPathToAppProfile )); 
    311300                        String line = null; 
    312301                         
Note: See TracChangeset for help on using the changeset viewer.