Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6327


Ignore:
Timestamp:
05/28/11 10:03:00 (13 years ago)
Author:
bfarka
Message:

added dokumentation for the service #1441

Location:
branches/OKBJavaConnector
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/OKBJavaConnector/AdministrationService/src/com/heuristiclab/okb/service/administration/AdministrationServiceUtil.java

    r6157 r6327  
    44 */
    55package com.heuristiclab.okb.service.administration;
    6 
    76
    87import com.heuristiclab.services.administration.AdministrationService;
     
    2322 */
    2423public final class AdministrationServiceUtil {
    25    
     24
     25    /**
     26     * workaround for getting the selfe signed certificates to work
     27     **/
    2628    static {
    27     // Create a trust manager that does not validate certificate chains
    28     TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
    29       public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    30         return new java.security.cert.X509Certificate[] {};
    31       }
     29        // Create a trust manager that does not validate certificate chains
     30        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
    3231
    33       public void checkClientTrusted(
    34           java.security.cert.X509Certificate[] certs, String authType) {
    35       }
     32        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
     33            return new java.security.cert.X509Certificate[]{};
     34        }
    3635
    37       public void checkServerTrusted(
    38           java.security.cert.X509Certificate[] certs, String authType) {
    39       }
    40     } };
     36        public void checkClientTrusted(
     37                java.security.cert.X509Certificate[] certs, String authType) {
     38        }
    4139
    42     SSLContext sc;
    43     try {
    44       sc = SSLContext.getInstance("SSL");
    45       sc.init(null, trustAllCerts, new java.security.SecureRandom());
    46       HttpsURLConnection
    47           .setDefaultSSLSocketFactory(sc.getSocketFactory());
    48     } catch (NoSuchAlgorithmException e) {
    49       throw new RuntimeException(e);
    50     } catch (KeyManagementException e) {
    51       throw new RuntimeException(e);
    52     }
     40        public void checkServerTrusted(
     41                java.security.cert.X509Certificate[] certs, String authType) {
     42        }
     43    }};
    5344
    54   }
    55    
    56     public static IAdministrationService createAdministrationService()
    57     {
    58         try
    59         {
    60      AdministrationService srv = new AdministrationService(new URL("https://services.heuristiclab.com/OKB.SPR.Java-3.3/AdministrationService.svc"));
     45        SSLContext sc;
     46        try {
     47            sc = SSLContext.getInstance("SSL");
     48            sc.init(null, trustAllCerts, new java.security.SecureRandom());
     49            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
     50        } catch (NoSuchAlgorithmException e) {
     51            throw new RuntimeException(e);
     52        } catch (KeyManagementException e) {
     53            throw new RuntimeException(e);
     54        }
     55
     56    }
     57
     58
     59    /**
     60     * getting an instance of the service
     61     * @return
     62     */
     63    protected static IAdministrationService createAdministrationService() {
     64        try {
     65            AdministrationService srv = new AdministrationService(new URL("https://services.heuristiclab.com/OKB.SPR.Java-3.3/AdministrationService.svc"));
    6166            IAdministrationService port = srv.getAdministrationService();
    6267            return port;
    63            
    64         }
    65         catch(MalformedURLException mue)
    66         {
     68
     69        } catch (MalformedURLException mue) {
    6770            throw new IllegalStateException(mue);
    6871        }
    6972    }
    7073
     74    /*
     75     * fetching a platform from the service
     76     */
     77    public static Platform getPlattform(String platformName) {
     78        Platform returnValue = null;
    7179
    72  
    73 
    74     public static Platform getPlattform(String platformName)
    75     {
    76         Platform returnValue = null;
    77        
    7880        IAdministrationService service = AdministrationServiceUtil.createAdministrationService();
    79         for(com.heuristiclab.services.administration.Platform o : service.getPlatforms().getPlatform())
    80         {
    81             if(o.getName().getValue().equals(platformName))
    82             {
     81        for (com.heuristiclab.services.administration.Platform o : service.getPlatforms().getPlatform()) {
     82            if (o.getName().getValue().equals(platformName)) {
    8383                returnValue = new Platform(o);
    8484            }
    8585        }
    86         if(returnValue == null)
    87         {
     86        if (returnValue == null) {
    8887            ObjectFactory of = new ObjectFactory();
    8988            com.heuristiclab.services.administration.Platform p = of.createPlatform();
    9089            p.setName(of.createString(platformName));
    91            
     90
    9291            p.setDescription(of.createString(platformName));
    9392            long id = createAdministrationService().addPlatform(p);
     
    9594
    9695        }
    97        
     96
    9897        return returnValue;
    9998    }
    100 
    101 
    10299}
  • branches/OKBJavaConnector/AdministrationService/src/com/heuristiclab/okb/service/administration/Platform.java

    r6157 r6327  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
     1
    52package com.heuristiclab.okb.service.administration;
    63
    74/**
    8  *
     5 * Value object for representing a platform
    96 * @author fab
    107 */
  • branches/OKBJavaConnector/ECJClient/src/com/heuristiclab/okb/ecj/OKBStatistics.java

    r6326 r6327  
    2323 *
    2424 * @author fab
     25 * Implementation of statics which are sending the parameters and results
     26 * to the OKB Serverices
     27 *
    2528 */
    26 public class OKBStatistics extends Statistics{
     29public class OKBStatistics extends Statistics {
    2730
     31    /**
     32     * Plattformname which has to be in already in the service
     33     */
    2834    public static final String ECJ_PLATFORM_NAME = "ECJ";
     35    /**
     36     * Name for parameters in the param file
     37     */
    2938    public static final String OKB_PARAMETER_NAME = "okb.parameter";
     39    /**
     40     * name of the seed paramter in the params file
     41     */
    3042    public static final String OKB_PARAMETER_SEED = "okb.parameter.seed";
     43    /**
     44     * username
     45     */
     46    public static final String OKB_USER = "okb.username";
     47    /**
     48     * password
     49     */
     50    public static final String OKB_PASSWORD = "okb.password";
     51    /**
     52     * current Platform
     53     * */
    3154    private Platform ecjPlatform;
    32    
     55    /**
     56     * current Alogrithm
     57     */
     58    private Algorithm algorithm;
    3359
    34 
     60    /**
     61     * Setup of statistic, username and password are set
     62     *
     63     * platform an algorithm are fetched from the service
     64     * if the platform or algorithm are missing a illegal arugement excption is thorwn
     65     **/
    3566    @Override
    3667    public void setup(EvolutionState state, Parameter base) {
    3768        super.setup(state, base);
    38    
    39        
     69        handler.UserNameHandler.setUser(getUsername(state));
     70        handler.UserNameHandler.setPassword(getPassword(state));
    4071
     72
     73        ecjPlatform = AdministrationServiceUtil.getPlattform(ECJ_PLATFORM_NAME);
     74        algorithm = RunCreationUtil.getAlgorithm(state.evaluator.getClass().getName(), ecjPlatform.getName());
    4175    }
    4276
    43 
    44 
    45     @Override
    46     public void postInitializationStatistics(EvolutionState state) {
    47         super.postInitializationStatistics(state);
    48     }
    49 
     77    /**
     78     * Submitting the results to the service
     79     * @param state
     80     * @param result
     81     */
    5082    @Override
    5183    public void finalStatistics(EvolutionState state, int result) {
    5284        super.finalStatistics(state, result);
    5385
    54        ecjPlatform = AdministrationServiceUtil.getPlattform(ECJ_PLATFORM_NAME);
    55        Algorithm algorithm = RunCreationUtil.getAlgorithm(state.evaluator.getClass().getName(), ecjPlatform.getName());
    56        Map<String, String> parameters = getParametersToSend(state);
    57        ByteArrayOutputStream o = new ByteArrayOutputStream();
    58        new XMLEncoder(o).writeObject(state);
    5986
    60 
    61        
    62         RunCreationUtil.createRun(parameters,result,new String(o.toByteArray()),getSeed(state),algorithm.getId() , ecjPlatform.getId());
     87        Map<String, String> parameters = getParametersToSend(state);
     88        ByteArrayOutputStream o = new ByteArrayOutputStream();
     89        new XMLEncoder(o).writeObject(state);
     90        RunCreationUtil.createRun(parameters, result, new String(o.toByteArray()), getSeed(state), algorithm.getId(), ecjPlatform.getId());
    6391
    6492    }
    6593
    66     private int getSeed(EvolutionState state)
    67     {
     94    /**
     95     * getting the username out of the config
     96     **/
     97    protected final String getUsername(EvolutionState state) {
     98        return state.parameters.getString(new Parameter(OKB_USER), null);
     99    }
     100
     101    /**
     102     * getting the password out of the config
     103     *
     104     */
     105    private String getPassword(EvolutionState state) {
     106        return state.parameters.getString(new Parameter(OKB_PASSWORD), null);
     107    }
     108
     109    /**
     110     * getting the default seed out of the config
     111     * @throws  IllegalArgumentException if the seed is missing
     112     */
     113    private int getSeed(EvolutionState state) {
    68114        int returnValue = 0;
    69         String seedName = state.parameters.getString(new Parameter(OKB_PARAMETER_SEED),null);
    70         if(seedName == null)
     115        String seedName = state.parameters.getString(new Parameter(OKB_PARAMETER_SEED), null);
     116        if (seedName == null) {
    71117            throw new IllegalArgumentException("no seed given!");
     118        }
    72119
    73         returnValue = state.parameters.getInt(new Parameter(seedName),null);
     120        returnValue = state.parameters.getInt(new Parameter(seedName), null);
    74121
    75122        return returnValue;
    76123    }
    77124
    78 
    79     private Map<String, String> getParametersToSend(EvolutionState state)
    80     {
     125    /**
     126     * getting the parameters out of the config
     127     **/
     128    private Map<String, String> getParametersToSend(EvolutionState state) {
    81129        Map<String, String> returnValue = new HashMap<String, String>();
    82         for(String name : state.parameters.getString(new Parameter(OKB_PARAMETER_NAME),null).split(";"))
    83         {
    84             String tmp = state.parameters.getString(new Parameter(name.trim()),null);
    85             if(tmp == null)
     130        for (String name : state.parameters.getString(new Parameter(OKB_PARAMETER_NAME), null).split(";")) {
     131            String tmp = state.parameters.getString(new Parameter(name.trim()), null);
     132            if (tmp == null) {
    86133                returnValue.put(name, name);
    87             else
     134            } else {
    88135                returnValue.put(name, tmp);
    89 
     136            }
    90137        }
    91 
    92138        return returnValue;
    93139    }
    94    
    95    
    96    
    97140}
  • branches/OKBJavaConnector/ECJClient/src/tutorial1.params

    r6326 r6327  
    5353eval.problem    = ec.app.tutorial1.MaxOnes
    5454
    55 
     55stat    = com.heuristiclab.okb.ecj.OKBStatistics
    5656okb.parameter = pop.subpop.0.size; pop.subpop.0.duplicate-retrie
    5757okb.parameter.seed = seed.0
     58okb.user = okbtester
     59okb.password = okbtester
  • branches/OKBJavaConnector/RunCreationService/nbproject/project.properties

    r6068 r6327  
    5656javadoc.version=false
    5757javadoc.windowtitle=
    58 main.class=
     58main.class=runcreationservice.Main
    5959manifest.file=manifest.mf
    6060meta.inf.dir=${src.dir}/META-INF
  • branches/OKBJavaConnector/RunCreationService/src/com/heurisitclab/okb/service/runcreation/Algorithm.java

    r6151 r6327  
    2323    }
    2424
     25    public Long getId()
     26    {
     27        return id;
     28    }
    2529
    2630}
  • branches/OKBJavaConnector/RunCreationService/src/com/heurisitclab/okb/service/runcreation/RunCreationUtil.java

    r6151 r6327  
    55package com.heurisitclab.okb.service.runcreation;
    66
     7import com.heuristiclab.services.runcreation.ArrayOfValue;
     8import com.heuristiclab.services.runcreation.DataType;
    79import com.heuristiclab.services.runcreation.IRunCreationService;
     10import com.heuristiclab.services.runcreation.IntValue;
     11import com.heuristiclab.services.runcreation.ObjectFactory;
    812import com.heuristiclab.services.runcreation.RunCreationService;
     13import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
     14
    915import java.net.MalformedURLException;
    1016import java.net.URL;
     17import java.util.Calendar;
     18import java.util.GregorianCalendar;
     19import java.util.Map;
     20import javax.xml.datatype.DatatypeFactory;
     21import javax.xml.datatype.XMLGregorianCalendar;
    1122
    1223/**
     
    1627public class RunCreationUtil {
    1728
    18     public static IRunCreationService createRunCreationService() {
     29    protected static IRunCreationService createRunCreationService() {
    1930        try {
    2031            RunCreationService srv = new RunCreationService(new URL("https://services.heuristiclab.com/OKB.SPR.Java-3.3/RunCreationService.svc"));
     
    2637        }
    2738    }
    28 
     39    /**
     40     * fetching an Algorithm by name and platformName from the service
     41     *@throws  IllegalArgumentException if no algorithm is found
     42     */
    2943    public static Algorithm getAlgorithm(String name, String platformName)
    3044    {
     
    4458        }
    4559
    46         return returnValue;
    47 
    48 
    49    
     60        return returnValue;   
    5061    }
    5162
    5263
    53     public static Run createRun()
     64    /**
     65     * submitting a run to the service
     66     */
     67    public static void createRun(Map<String, String> parameters, int result,String resultString,int seed, long algorithmId, long problemId)
    5468    {
    55        // Run returnValue = new Run();
    56        // com.heuristiclab.services.runcreation.Run r = null;
    57        // r.setAlgorithmId(Long.MIN_VALUE);
    58        // r.setClientId(null);
    59        // r.setProblemId(Long.MIN_VALUE);
    60        // r.setUserId(null);
    61        // createAdministrationService();
    6269
     70        com.heuristiclab.services.runcreation.ObjectFactory of = new com.heuristiclab.services.runcreation.ObjectFactory();
     71       
    6372
    64         return null;
     73        com.heuristiclab.services.runcreation.Run run = of.createRun();
     74       
     75        run.setAlgorithmId(algorithmId);
     76        run.setClientId(System.getProperties().getProperty("java.version"));
     77        run.setUserId("okbtester");
     78        run.setProblemId(problemId);
     79        Calendar cal = Calendar.getInstance();
     80       
     81        //of.createDateTime(XMLGregorianCalendarImpl.createDateTime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)));
     82
     83        run.setRandomSeed(seed);
     84
     85       ArrayOfValue values = of.createArrayOfValue();
     86        for(Map.Entry<String, String> param : parameters.entrySet())
     87        {
     88           
     89           com.heuristiclab.services.runcreation.StringValue v = of.createStringValue();
     90           v.setName(of.createValueName(param.getKey()));
     91           v.setValue(of.createStringValueValue(param.getValue()));
     92         
     93           values.getValue().add(v);
     94        }
     95     
     96       
     97
     98        run.setParameterValues(of.createRunParameterValues(values));
     99
     100        ArrayOfValue resultValues = new ArrayOfValue();
     101        IntValue value = new IntValue();
     102        value.setValue(result);
     103        value.setName(of.createValueName("integerResult"));
     104        resultValues.getValue().add(value);
     105        com.heuristiclab.services.runcreation.StringValue strValue = new com.heuristiclab.services.runcreation.StringValue();
     106        strValue.setName(of.createValueName("result"));
     107        strValue.setValue(of.createStringValueValue(resultString));
     108       
     109        resultValues.getValue().add(strValue);
     110       
     111        createRunCreationService().addRun(run);
    65112    }
    66113
    67114
    68 
    69 
    70115}
Note: See TracChangeset for help on using the changeset viewer.