JBoss AS 7 update system property via cli - configuration

I can read system properties via the CLI interface by
/system-property=propertyname:read-attribute(name="value")
Is there a simple way I can update the property via the CLI interface?

You can use the write-attribute operation to change system property values.
/system-property=propertyname:write-attribute(name="value", value="newValue")
See the answer below for a better description.

You can use the write-attribute operation.
A healthy workflow for the Management CLI is to expose, read and write resource attributes. To give an example of this workflow, we are going to doing the following steps on a fresh default installation of JBoss Application Server 7.1.0Beta1.
Steps to identify and write a system resource attribute
Read all system properties
Read a specific system property in more detail
Expose an example system property attribute
Write an example system property attribute
Expose the change to confirm it
Reset the attribute back to the original value
1. Read all system properties
We don't always know the exact name of what we are looking for. We can use a mix of tab completion and wildcard searches to make it easy to expose the resources and attributes. The read-resource operation is a great start to any workflow, as it exposes all present entities.
[domain#localhost:9999 /] /system-property=*:read-resource
{
"outcome" => "success",
"result" => [{
"address" => [("system-property" => "java.net.preferIPv4Stack")],
"outcome" => "success",
"result" => {
"boot-time" => true,
"value" => "true"
}
}]
}
2. Read a specific system property in more detail
The read-resource operation has exposed the java.net.preferIPv4Stack property. We can query this further by using the read-resource-description operation.
[domain#localhost:9999 /] /system-property=java.net.preferIPv4Stack:read-resource-description
{
"outcome" => "success",
"result" => {
"description" => "A system property to set on all servers in the domain.",
"head-comment-allowed" => true,
"tail-comment-allowed" => false,
"attributes" => {
"value" => {
"type" => STRING,
"description" => "The value of the system property.",
"required" => false,
"access-type" => "read-write",
"storage" => "configuration",
"restart-required" => "no-services"
},
"boot-time" => {
"type" => BOOLEAN,
"description" => "If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.",
"required" => false,
"default" => true,
"access-type" => "read-write",
"storage" => "configuration",
"restart-required" => "no-services"
}
}
}
}
3. Expose an example system property attribute
The read-resource-description operation prints information about the resource, including its attributes. We can specifically query these attributes with the read-attribute operation. Again, tab completion makes it easy to compose these operation strings as you begin typing, and hit tab to complete the string or to suggest available additions.
[domain#localhost:9999 /] /system-property=java.net.preferIPv4Stack:read-attribute(name=boot-time)
{
"outcome" => "success",
"result" => true
}
4. Write an example system property attribute
In the same way that we just queried the attribute, we can change it. In this case, we can use the write-attribute operation, keeping in mind the intended value type as reported by the read-resource-description operation. This operation declared the attributed to be BOOLEAN, but you should be able to work this out simply by looking at the existing value in the read-attribute command (where it is defined).
[domain#localhost:9999 /] /system-property=java.net.preferIPv4Stack:write-attribute(name=boot-time, value=false)
{
"outcome" => "success",
"result" => {
"domain-results" => {"step-1" => undefined},
"server-operations" => undefined
}
}
5. Expose the change to confirm it
We can run the read-attribute operation again to show the value change.
[domain#localhost:9999 /] /system-property=java.net.preferIPv4Stack:read-attribute(name=boot-time)
{
"outcome" => "success",
"result" => false
}
6. Reset the attribute back to the original value
Just to gracefully end the example, let's change the value back to the original state.
[domain#localhost:9999 /] /system-property=java.net.preferIPv4Stack:write-attribute(name=boot-time, value=true)
{
"outcome" => "success",
"result" => {
"domain-results" => {"step-1" => undefined},
"server-operations" => undefined
}
}
Summary
Yes, you can write attribute values. To make the process easier, a workflow habit of exposing the attribute values and file type definitions is a good practice, and should make the process clearer.

And for completeness, here's how to remove (undefine) a property attribute:
/system-property=propertyname:undefine-attribute(name=attribute-name)

Related

Using Laravel, is there a way to run validation on one ajax call with data for multiple models?

Assuming one were to post multiple data sets of one model at the time through JSON, it is possible to insert these using Eloquent's Model::create() function. However in my case I'll also need to validate this data.
The Validator only takes a Request object as input, and as far as I've seen I can't create a new Request instance with only one model.
Assuming this would be the input data (JSON), and index is the value for the browser to know what data belongs to an what item (as they have no unique ID assigned at the point of creation)
[
{
"index" : 1,
"name" : "Item 1",
"value" : "Some description"
},
{
"index" : 2,
"name" : "Item 2",
"value" : "Something to describe item 2"
},
(and so on)
]
Every object in the root array needs to be ran through the same validator. The rules of it are defined in Model::$rules (public static array).
Would there be a way to run the validator against every item, and possibly capture the errors per item?
You can utilize Validator for manual validation:
...
use Validator;
...
$validator = Validator::make(
json_decode($data, true), // where $data contains your JSON data string
[
// List your rules here using wildcard syntax.
'*.index' => 'required|integer',
'*.name' => 'required|min:2',
...
],
[
// Array of messages for validation errors.
...
],
[
// Array of attribute titles for validation errors.
...
]
);
if ($validator->fails()) {
// Validation failed.
// $validator->errors() will return MessageBag with what went wrong.
...
}
You can read more about validating arrays here.

Laravel 5.4 won't validate JSON

I'm using Laravel 5.4 and trying to validate JSON in my POST request however the validator fails stating that the JSON isn't valid, even though it is. I'm assuming I'm not understanding the validation rules correctly and my implementation is wrong, rather than a bug or something else.
I have a simple POST endpoint which has both the Accept and Content-Type headers set to application/json.
In my POST request (testing using Postman) I'm supplying RAW data.
{
"only_this_key": { "one": "two" }
}
In my controller method I have the following:
// I'm using intersect to remove any other parameters that may have been supplied as this endpoint only requires one
$requestData = $request->intersect(['only_this_key']);
$messages = [
'only_this_key.required' => 'The :attribute is required',
'only_this_key.json' => 'The :attribute field must be valid JSON',
];
$validator = \Validator::make($requestData, [
'only_this_key' => 'required|json',
], $messages);
if ($validator->fails()) {
return new APIErrorValidationResponse($request, $validator);
}
return response()->json(['all good' => 'here']);
The error I get back is The inventory field must be valid JSON even though it is!
Passing in the raw data using Postman
{
"only-this-key": {
"item-one": "one",
"item-two": "two",
"item-three": "three"
},
"not": "wanted"
}
When I use dd($request->all()); within the method
array:2 [
"what-i-want" => array:3 [
"item-one" => "one"
"item-two" => "two"
"item-three" => "three"
]
"not" => "wanted"
]
The problem is with how Laravel is interpreting the raw data in the request. If you run dd($request->all()) in your controller you will see this output:
array:1 [
"{"only_this_key":{"one":"two"}}" => ""
]
Your entire JSON string is getting set as a key with a value of an empty string. If you absolutely must send it as raw data, then you're going to have to grab that key value and save it to an array with the key that you want. This should work (instead of the intersect line).
$requestData = ['only_this_key' => key($request->all())];
Alternatively, you can just send the body as x-www-form-urlencoded with your entire JSON string as the only value for one key.

Parsing JSON file into logstash

Hi I am trying to send a json file with multiple objects to elasticsearch with the logstash so I can display the data using kibana. I have researched this extensively and simply cannot understand how to make the data formatted correctly to be used in kibana.
I have tried to use different filters such as: json, date, and grok
The issue is probably how I'm going about using these filters as I can't understand it's setup all to well.
Here is a sample line of the input json file:
{"time":"2015-09-20;12:13:24","bug_code":"tr","stacktrace":"543534"},
I want to use this format for displaying the data in kibana and sorting many objects according to their "time"
this following is what my current filter section is:
filter {
date {
match => ["time", "YYYY-MM-dd;HH:mm:ss Z" ]
timezone => "America/New_York"
locale => "en"
target => "#timestamp"
}
grok {
match => ["time", "%{TIMESTAMP_ISO8601:timestamp}"]
}
}
At this point I know the grok is wrong because I get "_grokparsefailure"
but how can I figure out the correct way to use grok or is there a simple way to sort the data using the given timestamp and not the processed timestamp given when sending the data through.
here is what the output currently shows:
"message" => "{\"time\":\"2015-09-20;12:13:24\",\"bug_code\":\"tr\",\"stacktrace\":\"543534\"},\r",
"#version" => "1",
"#timestamp" => "2015-11-23T09:54:50:274Z",
"host" => "<my_computer>",
"path" => "<path_to_.json>",
"type" => "json",
"tags" => [
[0] "_grokparsefailure"
any advice would be very much appreciated
You're almost there, I could get it working with a few tweaks.
First, you need to add the json{} filter in the first position. Then you need to change the date pattern to YYYY-MM-dd;HH:mm:ss and finally you can remove the grok filter at the end. You filter configuration would look like this:
filter {
json {
source => "message"
}
date {
match => ["time", "YYYY-MM-dd;HH:mm:ss" ]
timezone => "America/New_York"
locale => "en"
target => "#timestamp"
}
}
The parsed event for your sample JSON line would then look like this:
{
"message" => "{\"time\":\"2015-09-20;12:13:24\",\"bug_code\":\"tr\",\"stacktrace\":\"543534\"}",
"#version" => "1",
"#timestamp" => "2015-09-20T16:13:24.000Z",
"host" => "iMac.local",
"time" => "2015-09-20;12:13:24",
"bug_code" => "tr",
"stacktrace" => "543534"
}

Yii2 isGuest giving exception in console application

In console application when I used Yii::$app->user->isGuest it is giving the below exception:
Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown prop
erty: yii\console\Application::user'
I even tried adding the user in components array in config file. But it didn't worked. Any idea what am I doing wrong?
In Console application Yii->$app->user does not exist. So, you need to configure user component in config\console.php.
like as,
config\console.php
'components' => [
.........
......
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'app\models\User',
//'enableAutoLogin' => true,
],
'session' => [ // for use session in console application
'class' => 'yii\web\Session'
],
.......
]
To check it works or not using below code.
public function actionIndex($message = 'hello world')
{
echo $message . "\n";
$session = \Yii::$app->session->set('name', 'ASG');
if(\Yii::$app->session) // to check session works or not
echo \Yii::$app->session->get('name')."\n";
print_R(\Yii::$app->user);
}
More info about your problem : Link
Note : There's no session in console.
The reason is simple. Guide says about application components (user is a component):
user: represents the user authentication information. This component
is only available in Web applications Please refer to the
Authentication section for more details.
So Yii::$app->user it not available in console applications.
As a consequence you have to consider using this component in model classes that are also used by console applications.
Extra note: it is internally used by BlameableBehavior, however, this makes no problems since user will be null if a model gets saved/created and no user is available.

How can I select specific JSON attributes for jstree?

I have implemented a jstree which uses the json_data plugin to retrieve json data with ajax from a server. The json attributed for one node look like:
{"data":"1","uri":"http://www.abc.com/1"}
My problem now is, how can I save these attributes in the jstree nodes? I know that there's a "data" option looking like this:
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0
};
I'm relativley new to jquery and jstree and I don't know how I can use the data option to
assign these attributed to the nodes. This is important because I have to get the JSON data from the tree after it was changed (using create, rename, remove, dnd operations) and therefore the JSON has to look like the one which was initially requested from the server through ajax.
Can somebody help me?
Have a nice day!
You create your json jsTree structure + data + all attributes on server side.
jsTree receives json and displays it. There might be some way how to tweak the data in javascript once you received it. Make it simple and do it on server side.
Below is bit of my server side script in ruby that creates json structure. Note that year, month etc are custom attributes.
hash_tmp = {
"data" => dir,
"attr" => { "group" => group,
"build_name" => build_name,
"year" => year_tmp,
"month" => month_tmp,
"daytime" => daytime,
"action" => action,
"rel" => type,
},
"state" => state,
"children" => ""
}