cannot load Java class uk.co.jaywayco.Parser - jar

I am trying to write a custom logstash filter. I have followed the documentation here.
My filter (at the minute) looks like:
# Call this file 'foo.rb' (in logstash/filters, as above)
require "logstash/filters/base"
require "logstash/namespace"
class LogStash::Filters::NLP < LogStash::Filters::Base
# Setting the config_name here is required. This is how you
# configure this filter from your logstash config.
#
# filter {
# foo { ... }
# }
config_name "nlp"
# New plugins should start life at milestone 1.
milestone 1
# Replace the message with this value.
config :message, :validate => :string
public
def register
# nothing to do
java_import 'uk.co.jaywayco.Parser'
end # def register
public
def filter(event)
# return nothing unless there's an actual filter event
return unless filter?(event)
if #message
# Replace the event message with our message as configured in the
# config file.
event["message"] = #message
end
# filter_matched should go in the last line of our successful code
filter_matched(event)
end # def filter
end # class LogStash::Filters::NLP
Ive created a very simple logstash config that looks like this:
input {
stdin { type => "nlp" }
}
filter {
if [type] == "nlp" {
nlp {
message => "Hello world! - Youve been NLP'd"
}
}
}
output {
stdout { }
}
When i run logstash with the following command:
bin/logstash -f /etc/logstash/conf.d/test.conf
I get the following error:
The error reported is:
enter code herecannot load Java class uk.co.jaywayco.Parser
The java class uk.co.jaywayco.Parser is in a jar file located in the /opt/logstash/lib/logstash/filters folder. Which is where all the filter scripts reside.
Why wont logstash load my java class?

Ok so thanks to the logstash IRC channel
The solution was to add require 'logstash/filters/myjarfile.jar' wher the other requires are

Related

Can't create or update records in a loop, using ActiveStorage

Ruby 2.6.3
Rails 6.0.3
I don't why, when I try to create or update a record in a loop, adding an attachment or attachments, just only one or two recoreds can be updated. I also tested this behaviour with only one attachment and only for creating. But the behaviour is the same.
In the code below, I'm trying to reload attachments on aws, using active storage. But only 1 record is updated.
namespace :uploads do
task migrate_to_active_storage: :environment do
Upload.where.not(csv_file_name: nil).find_each do |upload|
%w[csv log].map do |attachment_type|
attach_url = [
'https://',
ENV['AWS_BUCKET'],
".s3-#{ENV['AWS_REGION']}.amazonaws.com/",
upload.business.normalized_name,
'/upload/',
upload.id.to_s,
"/#{attachment_type}/",
upload.csv_file_name
].join
upload.send(attachment_type).attach(
io: open(attach_url),
filename: upload["#{attachment_type}_file_name"],
content_type: upload["#{attachment_type}_content_type"]
)
end
end
ap 'DONe WITH SUCCESS' # never appears
end
end
I've managed to fix this, using threds. But I don't know why it doesn't work in the code above.
This solution works fine.
namespace :uploads do
task migrate_to_active_storage: :environment do
uploads = Thread.new { Upload.ids }.value
uploads.each do |id|
Thread.new do
sleep 2
upload = Upload.find id
upload.update csv: get_attachment(upload, 'csv'),
log: get_attachment(upload, 'log')
end.join
end
end
end
def get_attachment(upload, attachment_type)
attachment_url = [
'https://',
ENV['AWS_BUCKET'],
".s3-#{ENV['AWS_REGION']}.amazonaws.com/",
upload.business.normalized_name,
'/upload/',
upload.id.to_s,
"/#{attachment_type}/",
upload["#{attachment_type}_file_name"]
].join
{
io: open(attachment_url),
filename: "#{upload.id}_#{upload["#{attachment_type}_file_name"]}",
content_type: upload["#{attachment_type}_content_type"]
}
end
And what is really a mystic. When I try to call a differen model, for instance, like User. And even if it does nothing, the code above won't work. Only 1 record will'be updated.

How to pass a parameter from the Jupyter backend to a frontend extension

I currently have a value that is stored as an environment variable the environment where a jupyter server is running. I would like to somehow pass that value to a frontend extension. It does not have to read the environment variable in real time, I am fine with just using the value of the variable at startup. Is there a canonical way to pass parameters a frontend extension on startup? Would appreciate an examples of both setting the parameter from the backend and accessing it from the frontend.
[update]
I have posted a solution that works for nbextentions, but I can't seem to find the equivalent pattern for labextensions (typescript), any help there would be much appreciated.
I was able to do this by adding the following code to my jupter_notebook_config.py
from notebook.services.config import ConfigManager
cm = ConfigManager()
cm.update('notebook', {'variable_being_set': value})
Then I had the parameters defined in my extension in my main.js
// define default values for config parameters
var params = {
variable_being_set : 'default'
};
// to be called once config is loaded, this updates default config vals
// with the ones specified by the server's config file
var update_params = function() {
var config = Jupyter.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key) ){
params[key] = config.data[key];
}
}
};
I also have the parameters declared in my main.yaml
Parameters:
- name: variable_being_set
description: ...
input_type: text
default: `default_value`
This took some trial and error to find out because there is very little documentation on the ConfigManager class and none of it has an end-to-end example.

custom logging does not works when set in systemProperties

I want to change log configuration for a node for that I have written a custom xml file where I have changed some configuration related to some specific module and rolling policies and I am using command: java -Dlog4j.configurationFile=custom-log.xml -jar corda.jar
This works fine with my custom configuration, but when I set same configuration in systemProperties section of node.conf as:
systemProperties = {
-Dlog4j.configurationFile = custom-log.xml
}
It does not follow my custom logging configuration. Can you help me with this?
Instead of
systemProperties = {
-Dlog4j.configurationFile = custom-log.xml
}
pass it as this:
systemProperties = {
log4j.configurationFile = custom-log.xml
}
-D is automatically appended

JavaFX packager - can the name of the package icon be specified?

For a couple of years, I have been releasing updates to a modest app on a yearly basis -- just before the summer swim league starts up.
In the past, I have specified the various icons (volume, app, etc.) by placing them in the package/macosx/ folder. The filenames, MyApp-volume.icns etc., matched the <fx:application name="MyApp" .../> and everything worked just fine.
But starting with this year's build and deployment, the app's name will contain the year -- i.e., MyApp 2016. However, I don't want to be changing the icon filenames each year; I would like to keep them as they are (MyApp-volume.icns, MyApp.icns).
Is there a way to tell the Java packager to use a specific icon filename, one that is different from that of the app name or title? (I have looked at Oracle docs, but I don't see anything.)
-Bicon=<path to icon relative to project resourses>
is this what you looking for?
or you could just add it to your main app Stage.
hope it is usefull
As I wrote in my first comment to my question, javapackager doesn't have an option to do this.
Here's the solution that I worked out:
Create a new folder at the same level as the folder package (this doesn't refer to Java package but to Custom Resources). Name the new folder package-base.
Move the macosx and windows folders from package to package-base. (I don't produce an executable for Linux because none of my users use Linux.) Now, the package folder is empty.
In my build script, I added a step which, for every build that produces a "self-contained application package" (Oracle's terminology), cleans the package folder, and then copies the contents of package-base to package.
The files are renamed as they are copied to include the desired wording -- in my case, that means the year is appended to the filename. For example, MyApp-volume.icns when copied is renamed MyApp-2018-volume.icns.
Here are the relevant Gradle snippets:
import org.gradle.internal.os.OperatingSystem
...
def getYear() {
new Date().format('yyyy')
}
...
ext {
...
year = getYear()
appNameBase = "MyApp"
appName = appNameBase + " " + year
...
}
...
task macCleanPackage {
doLast {
if (OperatingSystem.current().isMacOsX()) {
delete fileTree(dir: "./package/macosx", include: "*.*")
}
}
}
task macCopyAndRenamePackageResources {
dependsOn macCleanPackage
doLast {
if (OperatingSystem.current().isMacOsX()) {
def toDir = "./package/macosx"
copy {
from './package-base/macosx'
into "${toDir}"
include "*${appNameBase}*.*"
rename { String fileName -> fileName.replace("$appNameBase", "${appName}") }
}
ant.replaceregexp(file: "${toDir}/${appName}-dmg-setup.scpt", match:"${appNameBase}", replace:"${appName}", flags:'g')
}
}
}
task windowsCleanPackage {
doLast {
if (OperatingSystem.current().isWindows()) {
delete fileTree(dir: "package/windows", includes: ["*.bmp", "*.ico", "*.iss"])
}
}
}
task windowsCopyAndRenamePackageResources {
dependsOn windowsCleanPackage
doLast {
if (OperatingSystem.current().isWindows()) {
def toDir = "./package/windows"
copy {
from './package-base/windows'
into "${toDir}"
include "*${appNameBase}*.*"
rename { String fileName -> fileName.replace("$appNameBase", "${appName}") }
}
// Replace app name in iss setup script to include year.
def issFilename = "./package/windows/${appName}.iss"
ant.replaceregexp(file: "${issFilename}", match: "${appNameBase}", replace: "${appName}", flags: "g")
ant.replaceregexp(file: "${issFilename}", match: "AppCopyright=Copyright (C)", replace: "AppCopyright=Copyright (C) ${year}", byline: "on")
ant.replaceregexp(file: "${issFilename}", match: "AppVersion=", replace: "AppVersion=${year} build ${buildNumber}", byline: "on")
ant.replaceregexp(file: "${issFilename}", match: "OutputBaseFilename=.*", replace: "OutputBaseFilename=${appName}-(build ${buildNumber})", byline: "on")
}
}
}
I don't just change filenames.
For the OS X release, ant.replaceregexp is used to modify the app's name in the custom AppleScript file.
For the Windows release, ant.replaceregexp is used extensively to replace version numbers, copyright, as well as the application's name (including the year) in the InnoSetup configuration file.
It may seem like a lot of extra work, but once the script is written, it just works.

PHPUnit inclusion path issues

This one's got me stumped. I've been working with PHPUnit for a couple of months now, so I'm not that green...but I look forward to being pointed in the direction of the obvious mistake I'm making! The initialisation process outlined below works fine if I run the "app" from a browser - but PHPUnit is choking...can any one put me out of my misery?
I'm trying to test a homebrew MVC, for study purposes. It follows a typical ZF layout.
Here's the index page:
include './../library/SKL/Application.php';
$SKL_Application = new SKL_Application();
$SKL_Application->initialise('./../application/configs/config.ini');
Here's the application class (early days...)
include 'bootstrap.php';
class SKL_Application {
/**
* initialises the application
*/
public function initialise($file) {
$this->processBootstrap();
//purely to test PHPUnit is working as expected
return true;
}
/**
* iterates over bootstrap class and executes
* all methods prefixed with "_init"
*/
private function processBootstrap() {
$Bootstrap = new Bootstrap();
$bootstrap_methods = get_class_methods($Bootstrap);
foreach ($bootstrap_methods as $method) {
if(substr($method,0,5) == '_init'){
$bootstrap->$method();
}
}
return true;
}
}
Here's the test:
require_once dirname(__FILE__).'/../../../public/bootstrap.php';
require_once dirname(__FILE__).'/../../../library/SKL/Application.php';
class SKL_ApplicationTest extends PHPUnit_Framework_TestCase {
protected $object;
protected function setUp() {
$this->object = new SKL_Application();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {
}
public function testInitialise() {
$this->assertType('boolean',$this->object->initialise());
}
}
But I keep stumbling at the first hurdle!!
PHP Warning: include(bootstrap.php): failed to open stream:
No such file or directory in path\to\files\SKL\Application.php on line 9
any ideas?
Use include_once or better yet require_once instead of include to include the bootstrap.php in the Application class file. Despite being already loaded include loads it again but since it's obviously not on the include path you get the error.
Thanks to Raoul Duke for giving me a push in the right direction, here's where I got to so far
1 - add the root of the application to the include path
2 - make all inclusion paths relative to the root of the application
3 - include a file in your unit tests that performs the same function, but compensates for the relative location when it is included. I just used realpath() on the directory location of the files.
The problem I have now is that the darn thing won't see any additional files I'm trying to pass it.
So, I'm trying to test a configuration class, that will parse a variety of filetypes dynamically. The directory structure is like this:
Application_ConfigTest.php
config.ini
The first test:
public function testParseFile() {
$this->assertType('array',$this->object->parseFile('config.ini'));
}
The error:
failed to open stream: No such file or directory
WTF? It's IN the same directory as the test class...
I solved this by providing an absolute (i.e. file structure) path to the configuration file.Can anyone explain to me how PHPUnit resolves it's paths, or is it because the test class itself is included elsewhere, rendering relative paths meaningless?

Resources