Refine search
public static String extractRequestKeyFromRequest(HttpServletRequest request) { Context context = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); String processedUrlPattern = context.getConfiguration().getAssetUrlPattern().startsWith("/") ? context.getConfiguration().getAssetUrlPattern().substring(1) : context.getConfiguration().getAssetUrlPattern(); Pattern p = Pattern.compile(processedUrlPattern + "([a-f0-9]{32})/[a-f0-9]{32}/"); Matcher m = p.matcher(request.getRequestURI()); String cacheKey = null; if (m.find()) { cacheKey = m.group(1); } return cacheKey; }
@Override public void init(FilterConfig filterConfig) throws ServletException { LOG.info("Initializing the Dandelion context"); context = new Context(filterConfig); LOG.info("Dandelion context initialized"); }
@Override public void destroy() { context.destroy(); } }
public void map(WritableComparable key, Writable val, Context context) throws IOException, InterruptedException { try{ Configuration config = context.getConfiguration(); String[] strs = val.toString().split(Constants.HIVE_RECORD_COLUMN_SEPARATOR); String family = config.get(Constants.CUBEBUILDER_CONFIGURATION_FAMILY); String column = strs[COLUMN_INDEX]; String Value = strs[VALUE_INDEX]; String sKey = generateKey(strs, config); byte[] bKey = Bytes.toBytes(sKey); Put put = new Put(bKey); put.add(Bytes.toBytes(family), Bytes.toBytes(column), (value <= 0) ? Bytes.toBytes(Double.MIN_VALUE) : Bytes.toBytes(value)); ImmutableBytesWritable ibKey = new ImmutableBytesWritable(bKey); context.write(ibKey, put); context.getCounter(CubeBuilderContextCounters.CompletedMapExecutions).increment(1); } catch(Exception e){ context.getCounter(CubeBuilderContextCounters.FailedMapExecutions).increment(1); } }
@Override protected void setup(Context context) throws IOException, InterruptedException { System.out.println("TRACE 1 " + context.getConfiguration().getClass().getName()); System.out.println("TRACE 2 " + context.getTaskAttemptID().toString()); System.out.println("TRACE 3 " + context.getInputSplit().toString()); }
@Override public boolean isApplicable(HandlerContext handlerContext) { return handlerContext.getContext().getConfiguration().isToolDebuggerEnabled() && handlerContext.getRequest().getParameter(WebConstants.DANDELION_CLEAR_STORAGE) != null; }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { getLogger().debug("Dandelion Asset servlet captured GET request {}", request.getRequestURI()); Context context = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); // Get the asset content thanks to the cache key String cacheKey = AssetUtils.extractCacheKeyFromRequest(request); AssetType assetType = AssetType.extractFromRequest(request); LOG.debug("Retrieved asset type: {}, cache key: {}", assetType, cacheKey); response.setContentType(assetType.getContentType() == null ? "text/plain" : assetType.getContentType()); // Write the asset content PrintWriter writer = response.getWriter(); writer.write(context.getAssetStorage().get(cacheKey).getContents()); // The response is explicitely closed here instead of setting a // Content-Length header writer.close(); }
@Override public boolean isApplicable(HandlerContext handlerContext) { HttpServletResponse wrappedResponse = handlerContext.getResponse(); HttpServletRequest request = handlerContext.getRequest(); boolean isJsProcessingEnabled = handlerContext.getContext().getConfiguration().isAssetJsProcessingEnabled(); boolean isHtmlRequest = wrappedResponse.getContentType() != null && wrappedResponse.getContentType().contains("text/html"); boolean notBrowsingDebugger = !request.getRequestURI().contains("ddl-debugger"); return isJsProcessingEnabled && isHtmlRequest && notBrowsingDebugger; }
@Override public String getAssetContent(HttpServletRequest request) { Context context = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); logger.debug("Generating asset..."); String generatedContent = getJavascriptContent(request); logger.debug("Asset generated successfully"); if (context.getConfiguration().isToolAssetPrettyPrintingEnabled()) { return ScriptingUtils.prettyPrintJs(generatedContent); } return generatedContent; }
@Override public boolean isApplicable(HandlerContext handlerContext) { // Retrieves the content type from the filtered response and remove // charset if present String mimeType = handlerContext.getResponse().getContentType(); boolean compatibleMimeType = StringUtils.isNotBlank(mimeType) && compatibleMimeTypes.contains(mimeType.split(";")[0]); String servletUrlPattern = handlerContext.getContext().getConfiguration().getAssetUrlPattern() .replaceAll("/\\*", ""); boolean matchesServletName = handlerContext.getRequest().getRequestURL().toString().contains(servletUrlPattern); LOG.trace("compatibleMimeType: {}, matchesServletName: {}", compatibleMimeType, matchesServletName); boolean isJsProcessingEnabled = handlerContext.getContext().getConfiguration().isAssetJsProcessingEnabled(); return isJsProcessingEnabled && compatibleMimeType && matchesServletName; }
@Override public InputStream getResourceAsStream(TemplateProcessingParameters templateProcessingParameters, String resourceName) { IContext context = templateProcessingParameters.getContext(); if (!(context instanceof IWebContext)) { throw new TemplateProcessingException("Resource resolution by ServletContext with " + this.getClass().getName() + " can only be performed " + "when context implements " + IWebContext.class.getName() + " [current context: " + context.getClass().getName() + "]"); } HttpServletRequest request = ((IWebContext) context).getHttpServletRequest(); Context dandelionContext = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); // Get the asset content thanks to the cache key String cacheKey = AssetUtils.extractCacheKeyFromRequest(request); String contents = dandelionContext.getAssetStorage().get(cacheKey).getContents(); // Wrap the contents with prototype-only comment blocks StringBuilder adaptedContents = new StringBuilder(BLOCK_WRAP_START); adaptedContents.append(BLOCK_WRAP_CDATA_START); adaptedContents.append(contents); adaptedContents.append(BLOCK_WRAP_CDATA_END); adaptedContents.append(BLOCK_WRAP_END); String configuredEncoding = dandelionContext.getConfiguration().getEncoding(); InputStream is = null; try { is = new ByteArrayInputStream(adaptedContents.toString().getBytes(configuredEncoding)); } catch (UnsupportedEncodingException e) { throw new DandelionException("Unable to encode the Javascript asset using the '" + configuredEncoding + "', which doesn't seem to be supported", e); } return is; }
Asset asset = handlerContext.getContext().getAssetStorage().get(cacheKey).getAsset(); .getRequest().getServletContext(), handlerContext.getRequest().getLocale()); RequestFlashData requestData = handlerContext.getContext().getRequestFlashDataCache().get(requestKey); processed = processed.replace(JsResourceResolver.BLOCK_WRAP_CDATA_END, ""); String configuredEncoding = handlerContext.getContext().getConfiguration().getEncoding(); Cache<String, RequestFlashData> cache = handlerContext.getContext().getRequestFlashDataCache(); Iterator<String> iterator = cache.keySet().iterator(); while (iterator.hasNext()) {
public void map(MD5Hash key, OverlapDataWritable value, Context context) Configuration conf = context.getConfiguration(); String someProperty = conf.get("something"); .... }
if (context.getConfiguration().isAssetMinificationEnabled()) { asset = this.context.getProcessorManager().process(asset, request); else if (context.getConfiguration().isAssetAutoVersioningEnabled() || assetLocator.isCachingForced()) { String contents = assetLocator.getContent(asset, request); this.context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, contents));
@Override public void setup(Context context) throws IOException, InterruptedException{ Configuration conf = context.getConfiguration(); Cluster cluster = new Cluster(conf); Job currentJob = cluster.getJob(context.getJobID()); mapperCounter = currentJob.getCounters().findCounter(COUNTER_NAME).getValue(); }
public Set<Alert> alerts() { Set<Alert> errors = new HashSet<Alert>(); String currentUri = UrlUtils.getCurrentUri(request).toString(); LOG.debug("Checking for alerts for the request \"{}\"", currentUri); String[] bundleNames = AssetRequestContext.get(this.request).getBundles(true); errors.addAll(this.context.getBundleStorage().alertsFor(bundleNames)); LOG.debug("-> Errors found: {}", errors.size()); return errors; }
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { FileSplit fileSplit = (FileSplit)context.getInputSplit(); FileSystem fs = FileSystem.get(context.getConfiguration()); FSDataInputStream in = fs.open(new Path(fileSplit.getPath().getParent() + "/file.txt")); while(in.available() > 0){ FSDataOutputStream out = fs.create(new Path(in.readLine())); } //Proceed further.... }
@Override protected Map<String, Object> getPageContext() { Map<String, Object> pageContext = new HashMap<String, Object>(); boolean cachingEnabled = context.getContext().getConfiguration().isCachingEnabled(); pageContext.put("cacheEnabled", cachingEnabled); if (cachingEnabled) { pageContext.put("implementation", context.getContext().getCache().getClass()); pageContext.put("cacheElements", context.getContext().getCache().getAll()); pageContext.put("getCount", context.getContext().getCache().getGetCount()); pageContext.put("hitCount", context.getContext().getCache().getHitCount()); pageContext.put("missCount", context.getContext().getCache().getMissCount()); pageContext.put("putCount", context.getContext().getCache().getPutCount()); } return pageContext; } }
if (!getContext().getBundleStorage().getBundleDag().getVertexMap().containsKey(bundleName)) { throw new DandelionException("The requested bundle \"" + bundleName + "\" does not exist in the graph."); .addAll(getContext().getBundleStorage().getBundleDag().getVertex(bundleName).getAssetStorageUnits()); Map<String, AssetLocator> locators = getContext().getAssetLocatorsMap();
@Override public boolean handle(HandlerContext handlerContext) { handlerContext.getContext().getAssetStorage().clear(); ; LOG.info("Cleared asset storage"); return true; } }