List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.pepstock.jem.ant.tasks.StepJava.java
/** * Replaces inside of property value system variables or properties loaded by ANT * @param value property value to change * @return value changed/*from w w w .jav a2s.com*/ */ private String replaceProperties(String value) { String changed = null; // if property starts with jem.data // I need to ask to DataPaths Container in which data path I can put the file if (value.startsWith("${" + ConfigKeys.JEM_DATA_PATH_NAME + "}")) { // takes the rest of file name String fileName = StringUtils.substringAfter(value, "${" + ConfigKeys.JEM_DATA_PATH_NAME + "}"); // checks all paths try { // gets datapaths PathsContainer paths = DataPathsContainer.getInstance().getPaths(fileName); // is relative! // creates a file with dataPath as parent, plus file name File file = new File(paths.getCurrent().getContent(), fileName); // the absolute name of the file is property value changed = file.getAbsolutePath(); } catch (InvalidDatasetNameException e) { throw new BuildException(e); } } else { // uses ANT utilities to changed all properties changed = getProject().replaceProperties(value); } return changed; }
From source file:org.pepstock.jem.ant.tasks.ValueParser.java
/** * Extract the sub token (value) considering blanks between = and prefix * @param token token to check inside the string * @param prefix prefix to check// ww w. ja va2s. c o m * @return the rest of the token string */ private static String getValue(String token, String prefix) { String subToken = StringUtils.substringAfter(token, prefix).trim(); // checks if there TOKEN=VALUE if (subToken.startsWith("=")) { return StringUtils.substringAfter(subToken, "=").trim(); } else { return null; } }
From source file:org.pepstock.jem.gwt.server.security.ExtendedJndiLdapRealm.java
/** * Extract from LDAP all configured attributes. * //from w w w .j av a 2s .c o m * @param id user id * @param environment LDAP environment * @return list of principal attributes */ public List<PrincipalAttribute> search(String id, Hashtable<String, String> environment) { // checks if attributes are set if (attributes != null && attributes.length > 0) { ctls.setReturningAttributes(attributes); } // if no attributes, uses UID by default if (ctls.getReturningAttributes() == null) { ctls.setReturningAttributes(new String[] { UID }); } // uses useDN for searching String userDn = super.getUserDnTemplate(); String ldapUserContext = StringUtils.substringAfter(userDn, ","); try { // gets initial context InitialDirContext ctx = new InitialDirContext(environment); // creates search string String filter = MessageFormat.format("(uid={0})", new Object[] { id }); // searchs! Object obj = ctx.search(ldapUserContext, filter, ctls); // scans all attributes and load into a Principal Attribute @SuppressWarnings("rawtypes") NamingEnumeration userEnum = (NamingEnumeration) obj; if (userEnum != null && userEnum.hasMore()) { SearchResult result = (SearchResult) userEnum.next(); return loadAttributes(id, result.getAttributes()); } } catch (NamingException ne) { LogAppl.getInstance().emit(UserInterfaceMessage.JEMG031E, ne, id); } return new ArrayList<PrincipalAttribute>(); }
From source file:org.pepstock.jem.jppf.ExecuteManager.java
/** * Create a JPPF job that can be submitted for execution. * //from w w w. jav a 2 s.c o m * @param runnable Class name of Runnable or JPPFTask to execute * @param parallelTaskNumber Number of parallel task to submit * @param xmlContext InitialContext, serialized in XML string * @return an instance of the {@link org.jppf.client.JPPFJob JPPFJob} class. * @throws NamingException * @throws IOException * @throws JPPFException * @throws JPFFException * if an error occurs while creating the job or adding tasks. */ private static JPPFJob createJob(String xmlContext) throws JPPFMessageException, NamingException, IOException, JPPFException { XStream xstream = new XStream(); // reads all properties String jobName = JPPFConfiguration.getProperties().getProperty(Keys.JEM_JOB_NAME); String taskName = JPPFConfiguration.getProperties().getProperty(Keys.JEM_TASK_NAME); String runnable = JPPFConfiguration.getProperties().getProperty(Keys.JEM_RUNNABLE); int parallelTaskNumber = JPPFConfiguration.getProperties().getInt(Keys.JEM_TASK_NUMBER); // creates a data provider to pass initial context and number of parallel task MemoryMapDataProvider provider = new MemoryMapDataProvider(); provider.setValue(Keys.JEM_CONTEXT, xmlContext); provider.setValue(Keys.JEM_TASK_NUMBER, String.valueOf(parallelTaskNumber)); // checks if CHUNK is set if (JPPFConfiguration.getProperties().containsKey(Keys.JEM_CHUNKABLE_DATA_DESCRIPTION)) { // gets data description String dataDescription = JPPFConfiguration.getProperties() .getProperty(Keys.JEM_CHUNKABLE_DATA_DESCRIPTION); File file = null; InitialContext ic = ContextUtils.getContext(); // lookup for JNDI reference // needs file name because chunk is based on RandomFileAccess // that wants a FILE and not inputstream // so gets data description implementation object // to get REAL FILE NamingEnumeration<NameClassPair> list = ic.list(dataDescription); while (list.hasMore()) { NameClassPair pair = list.next(); // checks if is datastream // only datastreams are searched if (pair.getName().equalsIgnoreCase(dataDescription) && pair instanceof DataStreamNameClassPair) { DataStreamNameClassPair dsPair = (DataStreamNameClassPair) pair; DataStreamReference prevReference = (DataStreamReference) dsPair.getObject(); // gets data description XML definition StringRefAddr sra = (StringRefAddr) prevReference.get(StringRefAddrKeys.DATASTREAMS_KEY); // creates datadescription implementatio to get file DataDescriptionImpl ddImpl = (DataDescriptionImpl) xstream.fromXML(sra.getContent().toString()); file = ddImpl.getDatasets().iterator().next().getRealFile(); // leaves while break; } } // if file is null // data description is not found if (file == null) { throw new JPPFMessageException(JPPFMessage.JEMJ019E, dataDescription); } // calculated buffersize long bufferSize = file.length() / parallelTaskNumber; // using delimiter, creates chunk list List<ChunkDefinition> chunks = null; String delimiter = JPPFConfiguration.getProperties().getProperty(Keys.JEM_DELIMITER); String delimiterString = JPPFConfiguration.getProperties().getProperty(Keys.JEM_DELIMITER_STRING); if (delimiter != null) { // delimiter default LF char splitter = CharUtils.LF; // if delimiter is defined in BYTE mode // calculate char if (delimiter.toLowerCase().startsWith("0x")) { delimiter = StringUtils.substringAfter(delimiter.toLowerCase(), "0x"); splitter = (char) Integer.parseInt(delimiter, 16); } else { // if uses a escape java char splitter = StringEscapeUtils.unescapeJava(delimiter).charAt(0); } String displayDelimiter = Integer.toHexString((byte) splitter) + "(" + splitter + ")"; LogAppl.getInstance().emit(JPPFMessage.JEMJ020I, displayDelimiter); // calculates chunks chunks = ChunksFactory.getChunksByDelimiter(file, bufferSize, splitter); provider.setValue(Keys.JEM_DELIMITER, splitter); } else if (delimiterString != null) { LogAppl.getInstance().emit(JPPFMessage.JEMJ020I, delimiterString); // calculates chunks chunks = ChunksFactory.getChunksByDelimiter(file, bufferSize, delimiterString); provider.setValue(Keys.JEM_DELIMITER, delimiterString); } else { // if delimiter and delimiterString are missing, uses default delimiter (System.getProperty("line.separator") chunks = ChunksFactory.getChunksByDelimiter(file, bufferSize); } // changes parallel task // because chunk calculation tries to maintain the same // number of task but usually there are less after // chunk list creation parallelTaskNumber = chunks.size(); LogAppl.getInstance().emit(JPPFMessage.JEMJ021I, chunks); // serializes and saves on data provider all necessary data provider.setValue(Keys.JEM_TASK_NUMBER, String.valueOf(parallelTaskNumber)); provider.setValue(Keys.JEM_CHUNKABLE_DATA_DESCRIPTION, dataDescription); provider.setValue(Keys.JEM_CHUNKS, xstream.toXML(chunks)); } LogAppl.getInstance().emit(JPPFMessage.JEMJ023I, parallelTaskNumber); // checks if merged data decritpion is an argument if (JPPFConfiguration.getProperties().containsKey(Keys.JEM_MERGED_DATA_DESCRIPTION)) { // loads a list with all temporary files for tasks // to use to write partial output for (int i = 0; i < parallelTaskNumber; i++) { File temp = File.createTempFile("task[" + i + "]-merge", ".jemjppf"); temp.deleteOnExit(); TEMPORARY_FILES.add(temp); LogAppl.getInstance().emit(JPPFMessage.JEMJ022I, temp.getAbsolutePath(), i); } // sets data provider provider.setValue(Keys.JEM_MERGED_DATA_DESCRIPTION, JPPFConfiguration.getProperties().getProperty(Keys.JEM_MERGED_DATA_DESCRIPTION)); provider.setValue(Keys.JEM_TEMPORARY_FILES, xstream.toXML(TEMPORARY_FILES)); } // create a JPPF job JPPFJob job = new JPPFJob(provider); // give this job a readable unique id that we can use to monitor and // manage it. job.setName(jobName + "." + taskName); // Checks what instance has been past to distribute on grid try { Object clazz = Class.forName(runnable).newInstance(); if (clazz instanceof JPPFTask) { for (int i = 0; i < parallelTaskNumber; i++) { JPPFTask t = new WrapperJPPFTask((JPPFTask) clazz); // add a task to the job. job.addTask(t); } } else if (clazz instanceof Runnable) { for (int i = 0; i < parallelTaskNumber; i++) { JPPFTask t = new RunnableTask((Runnable) clazz); // add a task to the job. job.addTask(t); } } else { throw new JPPFMessageException(JPPFMessage.JEMJ002E, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } } catch (InstantiationException e) { throw new JPPFMessageException(JPPFMessage.JEMJ002E, e, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } catch (IllegalAccessException e) { throw new JPPFMessageException(JPPFMessage.JEMJ002E, e, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } catch (ClassNotFoundException e) { throw new JPPFMessageException(JPPFMessage.JEMJ002E, e, runnable, Runnable.class.getName(), JPPFTask.class.getName()); } // there is no guarantee on the order of execution of the tasks, // however the results are guaranteed to be returned in the same order // as the tasks. return job; }
From source file:org.pepstock.jem.jppf.JPPFUtil.java
/** * Parses address, port and load JPPF properties to connect to JPPF. * @param props JPPF properties to load/*from ww w. j a va2 s.c o m*/ * @param addressParm address to parse * @throws JPPFMessageException if address is not valid */ public static void loadTypedProperties(TypedProperties props, String addressParm) throws JPPFMessageException { // parses addresses (comma separated) String address = StringUtils.remove(addressParm, " "); String[] addresses = StringUtils.split(address, ","); if (addresses != null && addresses.length > 0) { // calculate JPPF.DRIVERS properties StringBuilder drivers = new StringBuilder(); for (int i = 0; i < addresses.length; i++) { // parses address. FORMAT: [host|ipaddress]:[port] if (addresses[i].contains(":")) { String host = StringUtils.substringBefore(addresses[i], ":"); String port = StringUtils.substringAfter(addresses[i], ":"); // drivers is named with counter String driver = Keys.JEM_JPPF_DRIVER_PREFIX + i; props.setProperty(driver + Keys.JEM_JPPF_PORT_SUFFIX, port); props.setProperty(driver + Keys.JEM_JPPF_SERVER_SUFFIX, host); // drivers are defined blank separated drivers.append(driver).append(" "); } else { throw new JPPFMessageException(JPPFMessage.JEMJ008E, addresses[i]); } } // sets drivers props.setProperty(Keys.JEM_JPPF_DRIVERS, drivers.toString()); } }
From source file:org.pepstock.jem.node.affinity.SystemInfo.java
/** * Returns a properties object with network information.<br> * Keys are:<br>/*from www.j a v a 2 s . com*/ * <ul> * <li><code>ipaddresses</code>: list of ipaddresses of system</li> * <li><code>hostnames</code>: list of hostnames of system</li> * </ul> * * @return a mapping of environment variables to their value. */ public Properties getNetworkProperties() { // if the instance is null, // creates a new instance // otherwise it returns the previous instance if (network == null) { network = new Properties(); try { List<InetAddress> list = loadInetAddress(); // gets hostname from management String hostname = StringUtils.substringAfter(ManagementFactory.getRuntimeMXBean().getName(), "@"); // adds all ip addresses, formatting them network.setProperty("ipaddresses", formatAddresses(list)); network.setProperty("hostnames", hostname); } catch (Exception e) { // debug LogAppl.getInstance().debug(e.getMessage(), e); } } return network; }
From source file:org.pepstock.jem.node.https.SubmitHandler.java
@Override public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { // extracts the host String host = context.getAttribute(JOB_SUBMIT_IP_ADDRESS_KEY).toString(); // gets HTTP method (uses locale ENGLISH to be sure to have POST) String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); // if NOT post, exception! if (!method.equals(POST)) { LogAppl.getInstance().emit(NodeMessage.JEMC284W, method, host); throw new MethodNotSupportedException( NodeMessage.JEMC284W.toMessage().getFormattedMessage(method, host)); }/*www . j a va 2s . co m*/ // gets the URI or the request String target = request.getRequestLine().getUri(); // if is not the same , accepts, exception! if (!target.equalsIgnoreCase(DEFAULT_ACTION)) { LogAppl.getInstance().emit(NodeMessage.JEMC285W, target, host); throw new MethodNotSupportedException( NodeMessage.JEMC285W.toMessage().getFormattedMessage(target, host)); } // checks the HTTP request if (request instanceof HttpEntityEnclosingRequest) { // gets the entity of the request HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); // gets the body in string format String result = EntityUtils.toString(entity, CharSet.DEFAULT); // reads the first line, // with all URL encoded variables String vars = StringUtils.substringBefore(result, DELIMITER); // loads a map with all parms Map<String, String> parms = loadParametersMap(URLEncodedUtils.parse(vars, CharSet.DEFAULT)); // gets the USER String user = parms.get(SubmitParameters.USER.getName()); // if JEM is configured to have the Socket Interceptor on HC // the client MUST provide a SIGNATURE (using own private key) with // the user crypted inside if (Main.getHazelcastConfig().getNetworkConfig().getSocketInterceptorConfig().isEnabled()) { // checks if there is the signature if (parms.containsKey(USER_SIGNATURE_KEY)) { // gets the signature in HEX format String cryptedUserString = parms.get(USER_SIGNATURE_KEY); // gets keys stores KeyStoresInfo keyStoresInfo = KeyStoreUtil.getKeyStoresInfo(); try { // extracts from the USER key store the PUBLIC KEY (upload by UI) for the user PublicKey publicKey = KeysUtil.getPublicKeyByAlias(keyStoresInfo.getUserKeystoreInfo(), user); // creates tne SIGNATURE verifying steps Signature signature = Signature.getInstance("SHA256withRSA"); // sets public key signature.initVerify(publicKey); // sets content to check. It uses USER signature.update(user.getBytes(CharSet.DEFAULT_CHARSET_NAME)); // checks if is verified if (!signature.verify(Hex.decodeHex(cryptedUserString.toCharArray()))) { // if not, log and EXCEPTION LogAppl.getInstance().emit(NodeMessage.JEMC286W, user, host); throw new HttpException( NodeMessage.JEMC286W.toMessage().getFormattedMessage(user, host)); } } catch (MessageException e) { LogAppl.getInstance().emit(NodeMessage.JEMC286W, user, host); throw new ProtocolException(e.getMessage(), e); } catch (KeyException e) { throw new ProtocolException(e.getMessage(), e); } catch (DecoderException e) { throw new ProtocolException(e.getMessage(), e); } catch (NoSuchAlgorithmException e) { throw new ProtocolException(e.getMessage(), e); } catch (SignatureException e) { throw new ProtocolException(e.getMessage(), e); } } else { LogAppl.getInstance().emit(NodeMessage.JEMC287W, user, host); // if here, the signature is missing throw new HttpException(NodeMessage.JEMC287W.toMessage().getFormattedMessage(user, host)); } } // gets JEM environemnt name and its passwrod String env = parms.get(SubmitParameters.ENV.getName()); String password = parms.get(SubmitParameters.PASSWORD.getName()); // checks if password and env are same, // comparing with the HC configuration if (!Main.getHazelcastConfig().getGroupConfig().getName().equalsIgnoreCase(env) || !Main.getHazelcastConfig().getGroupConfig().getPassword().equalsIgnoreCase(password)) { // if not equals, exception LogAppl.getInstance().emit(NodeMessage.JEMC288W, host); throw new HttpException(NodeMessage.JEMC288W.toMessage().getFormattedMessage(host)); } // reads teh second row of the body, with the JCL String jcl = StringUtils.substringAfter(result, DELIMITER); // sets the entity to send back, submitting the job. // it returns the JOBID StringEntity resultEntity = new StringEntity(submit(jcl, user, host, parms), ContentType.create(RESPONSE_MIME_TYPE, CharSet.DEFAULT_CHARSET_NAME)); // sets STATUS code and entity response.setStatusCode(HttpStatus.SC_OK); response.setEntity(resultEntity); } else { // if here, the request is not correct LogAppl.getInstance().emit(NodeMessage.JEMC284W, method, host); throw new MethodNotSupportedException( NodeMessage.JEMC284W.toMessage().getFormattedMessage(method, host)); } }
From source file:org.pepstock.jem.node.NodeInfoUtility.java
/** * Factory creates a NodeInfo copying a set of information from Member * object of Hazelcast framework. NodeInfo will use Uuid of Member as the * key.// w w w .ja v a2s . c o m * * @see org.pepstock.jem.node.NodeInfo * @param member member object of Hazelcast framework * @param info node info to load * @throws NodeException if any exception occurs */ public static final void loadNodeInfo(Member member, NodeInfo info) throws NodeException { String jemVersion = getManifestAttribute(ConfigKeys.JEM_MANIFEST_VERSION); // sets the version if (jemVersion != null) { info.setJemVersion(jemVersion); } // set uuid of member of hazelcast as key info.setKey(member.getUuid()); // set status starting at the beginning info.setStatus(Status.STARTING); // sets boolean if has affinity loader // for net info of member, loads all info inside of nodeinfo // port of RMI will be set later InetSocketAddress address = member.getInetSocketAddress(); info.setPort(address.getPort()); info.setIpaddress(address.getAddress().getHostAddress()); // sets label to be displayed by GRS info.setLabel(info.getIpaddress() + ":" + info.getPort()); // sets execution environment info.setExecutionEnvironment(Main.EXECUTION_ENVIRONMENT); // use JMX to extract current process id info.setProcessId(ManagementFactory.getRuntimeMXBean().getName()); // extracts the name using the MXBean result String hostname = StringUtils.substringAfter(info.getProcessId(), "@"); info.setHostname(hostname); // extracts from operating ssytem MXbean all info about the ssytem OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean(); info.getNodeInfoBean().setSystemArchitecture(bean.getArch()); info.getNodeInfoBean().setAvailableProcessors(bean.getAvailableProcessors()); info.getNodeInfoBean().setSystemName(bean.getName()); // uses SIGAR to get total memory and the user used by JEM to start try { info.getNodeInfoBean().setTotalMemory(SIGAR.getMem().getTotal()); ProcCredName cred = SIGAR.getProcCredName(SIGAR.getPid()); info.setUser(cred.getUser()); } catch (SigarException e) { throw new NodeException(e.getMessage(), e); } // informs the node itself that it has been loaded info.loaded(); }
From source file:org.pepstock.jem.node.security.SecurityUtils.java
/** * Extract the right file name, used inside the permissions * @param fileName complete path/*from w w w . j a v a 2s .co m*/ * @return relative file name */ public String normalizeFileName(String fileName) { // gets data path String dataPath = DataPathsContainer.getInstance().getAbsoluteDataPath(fileName); // if not a data path, return file name as is if (dataPath != null) { // extract the filename, without the path of DATA path // because the permission are based on the file name // without the mount point of data path String file = StringUtils.substringAfter(fileName, dataPath); if (FilenameUtils.separatorsToSystem(file).startsWith(File.separator)) { return file.substring(1); } else { return file; } } return fileName; }
From source file:org.pepstock.jem.node.swarm.Swarm.java
/** * Initializes the nodeInfo that will be store in the SWARM NODES MAP * //www .ja va 2s . c o m * @see org.pepstock.jem.gwt.server.swarm.SwarmQueues#NODES_MAP * @param member this hazelcast member of the swarm environment */ private void initNodeInfo(Member member) { // set uuid of member of hazelcast as key nodeInfo.setKey(member.getUuid()); // set port and ip address InetSocketAddress address = member.getInetSocketAddress(); nodeInfo.setPort(address.getPort()); nodeInfo.setIpaddress(address.getAddress().getHostAddress()); // sets label to be displayed by GRS nodeInfo.setLabel(nodeInfo.getIpaddress() + ":" + nodeInfo.getPort()); // use JMX to extract current process id nodeInfo.setProcessId(ManagementFactory.getRuntimeMXBean().getName()); // set hostname String hostname = StringUtils.substringAfter(nodeInfo.getProcessId(), "@"); nodeInfo.setHostname(hostname); OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean(); nodeInfo.getNodeInfoBean().setSystemArchitecture(bean.getArch()); nodeInfo.getNodeInfoBean().setAvailableProcessors(bean.getAvailableProcessors()); nodeInfo.getNodeInfoBean().setSystemName(bean.getName()); ExecutionEnvironment executionEnvironment = new ExecutionEnvironment(); // the environment will be that of jem one not the swarm one. executionEnvironment.setEnvironment(Main.EXECUTION_ENVIRONMENT.getEnvironment()); nodeInfo.setExecutionEnvironment(executionEnvironment); nodeInfo.setJemVersion(Main.getNode().getJemVersion()); }