Ignore:
Timestamp:
11/26/13 11:56:07 (11 years ago)
Author:
wojtekp
Message:
 
Location:
DCWoRMS/branches/coolemall/src/simulator/workload
Files:
5 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                         
  • DCWoRMS/branches/coolemall/src/simulator/workload/reader/archive/AbstractWAParser.java

    r1144 r1207  
    3333        protected HashMap<String, String> reverseIdMapping; // key - xmlJobId_xmlTaskId, value - swf job id 
    3434        protected HashMap<String, Long> jobIndex; 
    35         protected HashMap<String, String> appMapping; 
     35        protected HashMap<String, String> appProfilesLocation; 
    3636        protected String fields[]; 
    3737        protected int fieldsNo; 
     
    4646                this.reverseIdMapping = new HashMap<String, String>(); 
    4747                this.jobIndex = new HashMap<String, Long>(); 
    48                 this.appMapping = new HashMap<String, String>(); 
     48                this.appProfilesLocation = new HashMap<String, String>(); 
    4949                this.headerLoaded = false; 
    5050                this.buildIndex = true; 
    5151                this.fieldsNo = 18; 
     52                 
    5253        } 
    5354 
     
    152153                                String appId = valueData[0]; 
    153154                                String pathToAppProfile = valueData[1]; 
    154                                 appMapping.put(appId, pathToAppProfile); 
     155                                appProfilesLocation.put(appId, pathToAppProfile); 
    155156                                continue; 
    156157                        } 
     
    296297         
    297298         
    298         public Map<String, String> getAppMapping() { 
    299                 return appMapping; 
     299        public Map<String, String> getAppProfilesLocation() { 
     300                return appProfilesLocation; 
    300301        } 
    301302         
  • DCWoRMS/branches/coolemall/src/simulator/workload/reader/archive/QcgWAJobReader.java

    r1163 r1207  
    1515 
    1616import simulator.workload.reader.archive.swf.SWFFields; 
     17 
     18import org.qcg.broker.schemas.jobdesc.FileType; 
    1719import org.qcg.broker.schemas.jobdesc.ResourceConsumptionProfileType; 
    1820import org.qcg.broker.schemas.jobdesc.Task; 
    1921import org.qcg.broker.schemas.jobdesc.Workflow; 
    2022 
    21 import dcworms.schedframe.scheduling.utils.JobDescription; 
     23import dcworms.schedframe.scheduling.utils.ApplicationProfileDescription; 
    2224 
    2325/** 
     
    116118        } 
    117119 
    118         public String mergeSwfAndXmlProfile(Map<String, JobDescription> applicationProfilesMap, String swfJobDesc) throws IOException{ 
     120        public String mergeSwfAndAppProfile(Map<String, ApplicationProfileDescription> applicationProfiles, String swfJobDesc) throws IOException{ 
    119121                 
    120122                StringReader reader = new StringReader(swfJobDesc); 
     
    132134                for(int i = 0; i < job.getTaskCount(); i++){ 
    133135                        try { 
    134                                 JobDescription xmlJobDescription = applicationProfilesMap.get(job.getTask(i).getExecution().getExecutable().getApplication().getAppProperty(0).getContent()); 
    135                                 if(xmlJobDescription != null){ 
    136                                         for(int j = 0; j < xmlJobDescription.size(); j++){ 
    137                                                 Task patternTask = xmlJobDescription.getDescription().getTask(j); 
    138                                                 if(patternTask != null){ 
    139                                                         ResourceConsumptionProfileType rcp = patternTask.getExecution().getResourceConsumptionProfile(); 
    140                                                         job.getTask(j).getExecution().setResourceConsumptionProfile(rcp); 
    141                                                 } 
     136                                ApplicationProfileDescription appProfileDescription = applicationProfiles.get(job.getTask(i).getExecution().getExecutable().getApplication().getAppProperty(0).getContent()); 
     137                                if(appProfileDescription != null){ 
     138                                        Task patternTask = appProfileDescription.getDescription(); 
     139                                        if(patternTask != null){ 
     140                                                ResourceConsumptionProfileType[] rcp = patternTask.getExecution().getResourceConsumptionProfile(); 
     141                                                job.getTask(i).getExecution().setResourceConsumptionProfile(rcp); 
     142                                                FileType script = new FileType(); 
     143                                                script.setName(patternTask.getId()); 
     144                                                job.getTask(i).getExecution().addStdin(script); 
    142145                                        } 
    143146                                }        
  • DCWoRMS/branches/coolemall/src/simulator/workload/reader/archive/WAParser.java

    r1144 r1207  
    4545        public int getType(); 
    4646         
    47         public Map<String, String> getAppMapping(); 
     47        public Map<String, String> getAppProfilesLocation(); 
    4848} 
  • DCWoRMS/branches/coolemall/src/simulator/workload/reader/archive/swf/QcgSWFJobReader.java

    r1202 r1207  
    221221                                         
    222222                                case SWFFields.DATA_EXECUTABLE_NUMBER: 
    223                                         String pathToAppProfile = waParser.getAppMapping().get(String.valueOf(value)); 
     223                                        String pathToAppProfile = waParser.getAppProfilesLocation().get(String.valueOf(value)); 
    224224                                        String appName = null; 
    225225                                        if(pathToAppProfile == null){ 
Note: See TracChangeset for help on using the changeset viewer.