public GeoserverWFSGenerator() { super(); this.supportedIDataTypes.add(GTVectorDataBinding.class); properties = WPSConfig.getInstance().getPropertiesForGeneratorClass(this.getClass().getName()); for (Property property : properties) { if (property.getName().equalsIgnoreCase("Geoserver_username")) { username = property.getStringValue(); } if (property.getName().equalsIgnoreCase("Geoserver_password")) { password = property.getStringValue(); } if (property.getName().equalsIgnoreCase("Geoserver_host")) { host = property.getStringValue(); } if (property.getName().equalsIgnoreCase("Geoserver_port")) { port = property.getStringValue(); } } if (port == null) { port = WPSConfig.getInstance().getWPSConfig().getServer().getHostport(); } for (String supportedFormat : supportedFormats) { if (supportedFormat.equals("text/xml")) { supportedFormats.remove(supportedFormat); } } }
public static RPropertyChangeManager getInstance() { if (instance == null) { instance = new RPropertyChangeManager(); WPSConfig.getInstance() .addPropertyChangeListener(WPSConfig.WPSCONFIG_PROPERTY_EVENT_NAME, instance); } return instance; }
public GenericTransactionalProcessRepository(String format) { Property[] properties = WPSConfig.getInstance().getPropertiesForRepositoryClass(this.getClass().getName()); // TODO think of multiple instance of this class registered (yet not possible since singleton) Property deployManagerXML = WPSConfig.getInstance().getPropertyForKey(properties, "DeployManager"); if (deployManagerXML == null) { throw new RuntimeException("Error. Could not find matching DeployManager"); } processDescriptionMap = new HashMap<String, ProcessDescriptionType>(); String className = deployManagerXML.getStringValue(); try { Class deployManagerClass = Class.forName(className); if (deployManagerClass.asSubclass(AbstractProcessManager.class).equals(deployManagerClass)) { Constructor constructor = deployManagerClass.getConstructor(ITransactionalAlgorithmRepository.class); deployManager = (IProcessManager) constructor.newInstance(this); } else { deployManager = (IProcessManager) deployManagerClass.newInstance(); } } catch (InstantiationException e) { e.printStackTrace(); throw new RuntimeException("Error. Could not find matching DeployManager"); } catch (IllegalAccessException e) { e.printStackTrace(); throw new RuntimeException("Error. Could not find matching DeployManager"); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new RuntimeException("Error. Could not find matching DeployManager"); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * After the client Request is accepted, it should be executed. To prevent resource-exhaustion, this * ThreadPoolExecutor stores the Requests in a queue, and handles only a couple of them at a time. * To tune the performance one can alter the parameters of this pool. * * <p>Proper pool size estimation: N = Number of processors WT = Average waiting time of a task ST = * Average service time of a task #Threads = N * (1 + WT/ST) * * @author Timon ter Braak */ public class RequestExecutor extends ThreadPoolExecutor { public static Server serverConfig = WPSConfig.getInstance().getWPSConfig().getServer(); /** Create a RequestExecutor. */ public RequestExecutor() { super( serverConfig.getMinPoolSize().intValue(), serverConfig.getMaxPoolSize().intValue(), serverConfig.getKeepAliveSeconds().intValue(), TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(serverConfig.getMaxQueuedTasks().intValue())); } }
private void executeGrassModuleStarter() { try { LOGGER.info("Executing GRASS module starter."); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(getCommand(), getEnvp()); PipedOutputStream pipedOut = new PipedOutputStream(); PipedInputStream pipedIn = new PipedInputStream(pipedOut); // attach error stream reader JavaProcessStreamReader errorStreamReader = new JavaProcessStreamReader(proc.getErrorStream(), "ERROR", pipedOut); // attach output stream reader JavaProcessStreamReader outputStreamReader = new JavaProcessStreamReader(proc.getInputStream(), "OUTPUT"); // start them errorStreamReader.start(); outputStreamReader.start(); // fetch errors if there are any BufferedReader errorReader = new BufferedReader(new InputStreamReader(pipedIn)); String line = errorReader.readLine(); String errors = ""; while (line != null) { errors = errors.concat(line + lineSeparator); line = errorReader.readLine(); } try { proc.waitFor(); } catch (InterruptedException e1) { LOGGER.error("Java proces was interrupted.", e1); } finally { proc.destroy(); } if (!errors.equals("")) { String baseDir = WebProcessingService.BASE_DIR + File.separator + "GRASS_LOGS"; File baseDirFile = new File(baseDir); if (!baseDirFile.exists()) { baseDirFile.mkdir(); } String host = WPSConfig.getInstance().getWPSConfig().getServer().getHostname(); if (host == null) { host = InetAddress.getLocalHost().getCanonicalHostName(); } String hostPort = WPSConfig.getInstance().getWPSConfig().getServer().getHostport(); File tmpLog = new File(tmpDir + fileSeparator + uuid + logFilename); File serverLog = new File(baseDir + fileSeparator + uuid + logFilename); if (tmpLog.exists()) { FileInputStream fis = new FileInputStream(tmpLog); FileOutputStream fos = new FileOutputStream(serverLog); try { byte[] buf = new byte[1024]; int i = 0; while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); } } catch (Exception e) { e.printStackTrace(); } finally { if (fis != null) fis.close(); if (fos != null) fos.close(); } } else { BufferedWriter bufWrite = new BufferedWriter(new FileWriter(serverLog)); bufWrite.write(errors); bufWrite.flush(); bufWrite.close(); } LOGGER.error("An error occured while executing the GRASS GIS process."); throw new RuntimeException( "An error occured while executing the GRASS GIS process. See the log under " + "http://" + host + ":" + hostPort + "/" + WebProcessingService.WEBAPP_PATH + "/GRASS_LOGS/" + uuid + logFilename + " for more details."); } } catch (IOException e) { LOGGER.error("An error occured while executing the GRASS GIS process.", e); throw new RuntimeException(e); } }
public void updateRepositoryConfiguration() { // Retrieve repository document and properties: String localRAlgorithmRepository_className = LocalRAlgorithmRepository.class.getCanonicalName(); Repository[] repositoryDocuments = WPSConfig.getInstance().getRegisterdAlgorithmRepositories(); Repository repositoryDocument = null; for (Repository doc : repositoryDocuments) { if (doc.getClassName().equals(localRAlgorithmRepository_className)) { repositoryDocument = doc; } } if (repositoryDocument == null) { LOGGER.error("Local R Algorithm Repository is not registered"); // return; } Property[] oldPropertyArray = repositoryDocument.getPropertyArray(); HashMap<String, Property> algorithmPropertyHash = new HashMap<String, Property>(); boolean propertyChanged = false; ArrayList<Property> newPropertyList = new ArrayList<Property>(); // test if host and port of rserve are available in config properties, if not, values from // R_Config // will be used // retrieve set of string representations for all config variables: HashSet<String> configVariableNames = new HashSet<String>(); for (RWPSConfigVariables var : RWPSConfigVariables.values()) { configVariableNames.add(var.toString().toLowerCase()); } for (Property property : oldPropertyArray) { String pname = property.getName().toLowerCase(); // check the name and active state if (pname.equalsIgnoreCase(RWPSConfigVariables.ALGORITHM.toString())) { LOGGER.debug("Algorithm property: " + property); // put id into a dictionary to check and add later: algorithmPropertyHash.put(property.getStringValue(), property); } else { LOGGER.debug("NOT-algorithm property: " + property); if (configVariableNames.contains(pname)) { boolean success = handleConfigVariable(property); if (!success) LOGGER.warn("Invalid config variable was omitted and deleted: " + property); // config variable should occur only once, doubling will be omitted: configVariableNames.remove(pname); } else { // valid properties which are not algorithms will be just passed to the new list LOGGER.debug("Unprocessed property: " + property); } newPropertyList.add(property); } } propertyChanged = checkMandatoryParameters( repositoryDocument, propertyChanged, newPropertyList, configVariableNames); propertyChanged = addMissingAlgorithms( repositoryDocument, algorithmPropertyHash, propertyChanged, newPropertyList); // there might be registered algorithms, which don't got a script file any more, // those will be deleted here: if (!algorithmPropertyHash.isEmpty()) propertyChanged = true; propertyChanged = checkPropertyOrder(oldPropertyArray, propertyChanged); if (propertyChanged) { Property[] newPropertyArray = newPropertyList.toArray(new Property[0]); // sort list of properties lexicographically: Arrays.sort(newPropertyArray, new PropertyComparator()); repositoryDocument.setPropertyArray(newPropertyArray); propertyChanged = true; // write new WPSConfig if property had to be changed WPSConfigurationDocument wpsConfigurationDocument = WPSConfigurationDocument.Factory.newInstance(); WPSConfiguration wpsConfig = WPSConfig.getInstance().getWPSConfig(); wpsConfigurationDocument.setWPSConfiguration(wpsConfig); // writes the new WPSConfig to a file try { String configurationPath = WPSConfig.getConfigPath(); File XMLFile = new File(configurationPath); wpsConfigurationDocument.save( XMLFile, new org.apache.xmlbeans.XmlOptions().setUseDefaultNamespace().setSavePrettyPrint()); WPSConfig.forceInitialization(configurationPath); LOGGER.info("WPS Config was changed."); } catch (IOException e) { LOGGER.error("Could not write configuration to file: " + e.getMessage()); } catch (org.apache.xmlbeans.XmlException e) { LOGGER.error("Could not generate XML File from Data: " + e.getMessage()); } } }
public static RPropertyChangeManager reInitialize() { WPSConfig.getInstance() .removePropertyChangeListener(WPSConfig.WPSCONFIG_PROPERTY_EVENT_NAME, instance); instance = new RPropertyChangeManager(); return instance; }