Changeset 6327
- Timestamp:
- 05/28/11 10:03:00 (14 years ago)
- Location:
- branches/OKBJavaConnector
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKBJavaConnector/AdministrationService/src/com/heuristiclab/okb/service/administration/AdministrationServiceUtil.java
r6157 r6327 4 4 */ 5 5 package com.heuristiclab.okb.service.administration; 6 7 6 8 7 import com.heuristiclab.services.administration.AdministrationService; … … 23 22 */ 24 23 public final class AdministrationServiceUtil { 25 24 25 /** 26 * workaround for getting the selfe signed certificates to work 27 **/ 26 28 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() { 32 31 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 } 36 35 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 } 41 39 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 }}; 53 44 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")); 61 66 IAdministrationService port = srv.getAdministrationService(); 62 67 return port; 63 64 } 65 catch(MalformedURLException mue) 66 { 68 69 } catch (MalformedURLException mue) { 67 70 throw new IllegalStateException(mue); 68 71 } 69 72 } 70 73 74 /* 75 * fetching a platform from the service 76 */ 77 public static Platform getPlattform(String platformName) { 78 Platform returnValue = null; 71 79 72 73 74 public static Platform getPlattform(String platformName)75 {76 Platform returnValue = null;77 78 80 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)) { 83 83 returnValue = new Platform(o); 84 84 } 85 85 } 86 if(returnValue == null) 87 { 86 if (returnValue == null) { 88 87 ObjectFactory of = new ObjectFactory(); 89 88 com.heuristiclab.services.administration.Platform p = of.createPlatform(); 90 89 p.setName(of.createString(platformName)); 91 90 92 91 p.setDescription(of.createString(platformName)); 93 92 long id = createAdministrationService().addPlatform(p); … … 95 94 96 95 } 97 96 98 97 return returnValue; 99 98 } 100 101 102 99 } -
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 5 2 package com.heuristiclab.okb.service.administration; 6 3 7 4 /** 8 * 5 * Value object for representing a platform 9 6 * @author fab 10 7 */ -
branches/OKBJavaConnector/ECJClient/src/com/heuristiclab/okb/ecj/OKBStatistics.java
r6326 r6327 23 23 * 24 24 * @author fab 25 * Implementation of statics which are sending the parameters and results 26 * to the OKB Serverices 27 * 25 28 */ 26 public class OKBStatistics extends Statistics {29 public class OKBStatistics extends Statistics { 27 30 31 /** 32 * Plattformname which has to be in already in the service 33 */ 28 34 public static final String ECJ_PLATFORM_NAME = "ECJ"; 35 /** 36 * Name for parameters in the param file 37 */ 29 38 public static final String OKB_PARAMETER_NAME = "okb.parameter"; 39 /** 40 * name of the seed paramter in the params file 41 */ 30 42 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 * */ 31 54 private Platform ecjPlatform; 32 55 /** 56 * current Alogrithm 57 */ 58 private Algorithm algorithm; 33 59 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 **/ 35 66 @Override 36 67 public void setup(EvolutionState state, Parameter base) { 37 68 super.setup(state, base); 38 39 69 handler.UserNameHandler.setUser(getUsername(state)); 70 handler.UserNameHandler.setPassword(getPassword(state)); 40 71 72 73 ecjPlatform = AdministrationServiceUtil.getPlattform(ECJ_PLATFORM_NAME); 74 algorithm = RunCreationUtil.getAlgorithm(state.evaluator.getClass().getName(), ecjPlatform.getName()); 41 75 } 42 76 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 */ 50 82 @Override 51 83 public void finalStatistics(EvolutionState state, int result) { 52 84 super.finalStatistics(state, result); 53 85 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);59 86 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()); 63 91 64 92 } 65 93 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) { 68 114 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) { 71 117 throw new IllegalArgumentException("no seed given!"); 118 } 72 119 73 returnValue = state.parameters.getInt(new Parameter(seedName), null);120 returnValue = state.parameters.getInt(new Parameter(seedName), null); 74 121 75 122 return returnValue; 76 123 } 77 124 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) { 81 129 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) { 86 133 returnValue.put(name, name); 87 else134 } else { 88 135 returnValue.put(name, tmp); 89 136 } 90 137 } 91 92 138 return returnValue; 93 139 } 94 95 96 97 140 } -
branches/OKBJavaConnector/ECJClient/src/tutorial1.params
r6326 r6327 53 53 eval.problem = ec.app.tutorial1.MaxOnes 54 54 55 55 stat = com.heuristiclab.okb.ecj.OKBStatistics 56 56 okb.parameter = pop.subpop.0.size; pop.subpop.0.duplicate-retrie 57 57 okb.parameter.seed = seed.0 58 okb.user = okbtester 59 okb.password = okbtester -
branches/OKBJavaConnector/RunCreationService/nbproject/project.properties
r6068 r6327 56 56 javadoc.version=false 57 57 javadoc.windowtitle= 58 main.class= 58 main.class=runcreationservice.Main 59 59 manifest.file=manifest.mf 60 60 meta.inf.dir=${src.dir}/META-INF -
branches/OKBJavaConnector/RunCreationService/src/com/heurisitclab/okb/service/runcreation/Algorithm.java
r6151 r6327 23 23 } 24 24 25 public Long getId() 26 { 27 return id; 28 } 25 29 26 30 } -
branches/OKBJavaConnector/RunCreationService/src/com/heurisitclab/okb/service/runcreation/RunCreationUtil.java
r6151 r6327 5 5 package com.heurisitclab.okb.service.runcreation; 6 6 7 import com.heuristiclab.services.runcreation.ArrayOfValue; 8 import com.heuristiclab.services.runcreation.DataType; 7 9 import com.heuristiclab.services.runcreation.IRunCreationService; 10 import com.heuristiclab.services.runcreation.IntValue; 11 import com.heuristiclab.services.runcreation.ObjectFactory; 8 12 import com.heuristiclab.services.runcreation.RunCreationService; 13 import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl; 14 9 15 import java.net.MalformedURLException; 10 16 import java.net.URL; 17 import java.util.Calendar; 18 import java.util.GregorianCalendar; 19 import java.util.Map; 20 import javax.xml.datatype.DatatypeFactory; 21 import javax.xml.datatype.XMLGregorianCalendar; 11 22 12 23 /** … … 16 27 public class RunCreationUtil { 17 28 18 p ublicstatic IRunCreationService createRunCreationService() {29 protected static IRunCreationService createRunCreationService() { 19 30 try { 20 31 RunCreationService srv = new RunCreationService(new URL("https://services.heuristiclab.com/OKB.SPR.Java-3.3/RunCreationService.svc")); … … 26 37 } 27 38 } 28 39 /** 40 * fetching an Algorithm by name and platformName from the service 41 *@throws IllegalArgumentException if no algorithm is found 42 */ 29 43 public static Algorithm getAlgorithm(String name, String platformName) 30 44 { … … 44 58 } 45 59 46 return returnValue; 47 48 49 60 return returnValue; 50 61 } 51 62 52 63 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) 54 68 { 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();62 69 70 com.heuristiclab.services.runcreation.ObjectFactory of = new com.heuristiclab.services.runcreation.ObjectFactory(); 71 63 72 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); 65 112 } 66 113 67 114 68 69 70 115 }
Note: See TracChangeset
for help on using the changeset viewer.