I am attempting to remove ALL version of java from windows PATH via Puppet.
I will replace it with %JAVA_HOME%\bin.
Here is the current code:
include windows_path
define obsolete_java {
windows_path {
$name:
ensure => absent,
directory => "C:\\Program Files\\Java\\$name\\bin";
}
}
define windows_java::setup (
$ensure = 'present',
$source = undef,
$file = undef,
$package = undef ) {
case $::osfamily {
Windows : { $supported = true }
default : { fail("The ${module_name} module is not supported on ${::osfamily} based systems") }
}
# Validate parameters
if ($source == undef) {
fail('source parameter must be set')
}
if ($file == undef) {
fail('file parameter must be set')
}
if ($package == undef) {
fail('package parameter must be set')
}
# Validate input values for $ensure
if !($ensure in ['present', 'absent']) {
fail('ensure must either be present or absent')
}
if ($caller_module_name == undef) {
$mod_name = $module_name
} else {
$mod_name = $caller_module_name
}
if ($ensure == 'present'){
# ensures main directory exists
file {'C:\Program Files\Java':
ensure => directory,
}
# copies source executable over
file { "C:\\Program Files\\Java\\$source":
ensure => present,
source => "puppet:///extra_files/java/windows/$source",
before => Package["$package"],
source_permissions => ignore,
}
# Name of package must match name when installed
package { "$package":
ensure => installed,
source => "C:\\Program Files\\java\\$source",
install_options => '/s',
}
# sets JAVA_HOME. If already existant, replaces it.
windows_env { "JAVA_HOME=C:\\Program Files\\Java\\$file":
mergemode => clobber,
}
# removes previous Java from path
obsolete_java {'jdk1.7.0_51':}
# Adds JAVA_HOME to the path.
windows_path {'javaPath':
ensure => present,
directory => "%JAVA_PATH%\bin",
}
} else {
package { 'remove-package':
name => "$package",
ensure => absent,
}
windows_env { 'JAVA_HOME':
ensure => 'absent',
mergemode => clobber,
}
windows_path {'remove_java_path':
ensure => absent,
directory => "C:\\Program Files\\Java\\$file\\bin",
}
}
}
Specifically:
define obsolete_java {
windows_path {
$name:
ensure => absent,
directory => "C:\\Program Files\\Java\\$name\\bin";
}
}
called here:
# removes previous Java from path
obsolete_java {'jdk1.7.0_51':}
Is it possible just have it remove anything it finds under: C:\Program Files\Java\any_jdk
bin ?
Edit: More importantly, can I force it to find any directory that contains the word "java" and remove it from PATH?
Seeing as the windows_path type is somewhat complex, there seems to be no conceivable way for the provider to prefetch the full list of existing paths. You will therefor be unable to purge the java paths.
That leaves you with only one option that I can see: Create an external fact (or plain custom fact) to retrieve the list of directories in the PATH. If you don't use Facter 2, you will need to get the delimited PATH string and process it on the master. Facter 2 can hand an array to the master.
If you have them in a variable, say $path_list, you can hand them to a similar defined type as the one you are using already.
filter_path { $path_list: }
define filter_path {
if $name =~ /java/ {
windows_path { $name: ensure => absent, directory => $name }
}
}
Related
this is my conf. file
input {
file {
type => "java"
path => "/UUUU********/IdeaProjects/elk-stack-logging-example/elk-example.log"
codec => multiline {
pattern => "^%{YEAR}-%{MONTHNUM}-%{MONTHDAY} %{TIME}.*"
negate => "true"
what => "previous"
}
}
}
filter {
#If log line contains tab character followed by 'at' then we will tag that entry as stacktrace
if [message] =~ "\tat" {
grok {
match => ["message", "^(\tat)"]
add_tag => ["stacktrace"]
}
}
grok {
match => [ "message",
"(?<timestamp>%{YEAR}-%{MONTHNUM}-%{MONTHDAY} %{TIME}) %{LOGLEVEL:level} %{NUMBER:pid} --- \[(?<thread>[A-Za-z0-9-]+)\] [A-Za-z0-9.]*\.(?<class>[A-Za-z0-9#_]+)\s*:\s+(?<logmessage>.*)",
"message",
"(?<timestamp>%{YEAR}-%{MONTHNUM}-%{MONTHDAY} %{TIME}) %{LOGLEVEL:level} %{NUMBER:pid} --- .+? :\s+(?<logmessage>.*)"
]
}
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss.SSS" ]
}
}
output {
# Sending properly parsed log events to elasticsearch
elasticsearch {
hosts => ['https://**********************:9243/']
user => 'elastic'
password => '*********************'
index => "logstash_%{+YYYYMMdd}"
}
stdout { codec => rubydebug }
}
after running the code I go to elastic search then I want to create a data view inserting the name log stash it says not data stream or index found for a given name.
How to make this conf file work and create that index so I can create the view
I'm using JIB (not super relevant) and I want to pass in variables from command line in my deployment script.
I append using -PinputTag=${DOCKER_TAG} -PbuildEnv=nonprod in my gradle command, which is cool. But when it's missing, I want that ternary to kick in.
I'm getting the error:
Could not get unknown property 'inputTag' for project ':webserver' of type org.gradle.api.Project.
def inputTag = inputTag ?: 'latest'
def buildEnv = buildEnv ?: 'nonprod'
jib {
container {
mainClass = 'com.example.hi'
}
to {
image = 'image/cool-image'
tags = ['latest', inputTag]
}
container {
creationTime = 'USE_CURRENT_TIMESTAMP'
ports = ['8080']
jvmFlags = ['-Dspring.profiles.active=' + buildEnv]
}
}
Found Solution
def inputTag = project.hasProperty('inputTag') ? project.property('inputTag') : 'latest'
def buildEnv = project.hasProperty('buildEnv') ? project.property('buildEnv') : 'nonprod'
This seems to be working, is this the best way?
How about this?
image = 'image/cool-image:' + (project.findProperty('inputTag') ?: 'latest')
Note jib.to.tags are additional tags. jib.to.image = 'image/cool-image' already implies image/cool-image:latest, so no need to duplicate latest in jib.to.tags.
How can I access resources from dependencies? I have something like this:
Wrapper project build.gradle
..
dependencies {
compile com.company:mysubproject1:2.0.1
compile com.company:mysubproject2:2.0.1
..
Those subprojects have some files in THEIR resource directories e.g. src/main/resources/liquibase/changelog.xml
There can be n of these subprojects and I need my gradle task to
pass through all dependencies and grab all changelog.xml files and create new file from them which will be later used.
It was actually not that hard:
doFirst {
println 'Generating master changelog...'
def changelogFiles = []
configurations.runtime.each {
def zip = new ZipFile(it)
def entries = zip.entries()
entries.findAll { entry -> entry.name.contains("liquibase") }
.findAll { entry -> entry =~ /changelog.xml/ }
.each { entry ->
changelogFiles.add(((ZipEntry) entry).name)
}
}
def resDir = sourceSets.main.output.resourcesDir.path + '/liquibase'
def changelogFile = new File("$resDir/changelog-master.xml")
changelogFile.write("<databaseChangeLog xmlns=\"http://www.liquibase.org/xml/ns/dbchangelog\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd\">\n\n")
changelogFiles.each {
println("Including $it to changelog.")
changelogFile << " <include file=\"classpath:$it\"/> \n"
}
changelogFile << "\n</databaseChangeLog>"
}
This code just loops through dependencies and digs up file paths for files named 'changelog.xml' and having 'liquibase' in path.
Possible issue would be if 2 dependecies had file with same name and path, I don't know what would be on classpath in that case.
How create a REGEX to detect if a "String url" contains a file extension (.pdf,.jpeg,.asp,.cfm...) ?
Valids (without extensions):
http://www.yahoo.com
http://dbpedia.org/ontology/
http://www.rdf.com.br
Invalids (with extensions):
http://www.thesis.com/paper.pdf
http://pics.co.uk/mypic.png
http://jpeg.com/images/cool/the_image.JPEG
Thanks,
Celso
In Java, you are better off using String.endsWith() This is faster and easier to read.
Example:
"file.jpg".endsWith(".jpg") == true
Alternative version without regexp but using, the URI class:
import java.net.*;
class IsFile {
public static void main( String ... args ) throws Exception {
URI u = new URI( args[0] );
for( String ext : new String[] {".png", ".pdf", ".jpg", ".html" } ) {
if( u.getPath().endsWith( ext ) ) {
System.out.println("Yeap");
break;
}
}
}
}
Works with:
java IsFile "http://download.oracle.com/javase/6/docs/api/java/net/URI.html#getPath()"
How about this?
// assuming the file extension is either 3 or 4 characters long
public boolean hasFileExtension(String s) {
return s.matches("^[\\w\\d\\:\\/\\.]+\\.\\w{3,4}(\\?[\\w\\W]*)?$");
}
#Test
public void testHasFileExtension() {
assertTrue("3-character extension", hasFileExtension("http://www.yahoo.com/a.pdf"));
assertTrue("3-character extension", hasFileExtension("http://www.yahoo.com/a.htm"));
assertTrue("4-character extension", hasFileExtension("http://www.yahoo.com/a.html"));
assertTrue("3-character extension with param", hasFileExtension("http://www.yahoo.com/a.pdf?p=1"));
assertTrue("4-character extension with param", hasFileExtension("http://www.yahoo.com/a.html?p=1&p=2"));
assertFalse("2-character extension", hasFileExtension("http://www.yahoo.com/a.co"));
assertFalse("2-character extension with param", hasFileExtension("http://www.yahoo.com/a.co?p=1&p=2"));
assertFalse("no extension", hasFileExtension("http://www.yahoo.com/hello"));
assertFalse("no extension with param", hasFileExtension("http://www.yahoo.com/hello?p=1&p=2"));
assertFalse("no extension with param ends with .htm", hasFileExtension("http://www.yahoo.com/hello?p=1&p=a.htm"));
}
Not a Java developer anymore, but you could define what you're looking for with the following regex
"/\.(pdf|jpe{0,1}g|asp|docx{0,1}|xlsx{0,1}|cfm)$/i"
Not certain what the function would look like.
If the following code returns true, then contains a file extension in the end:
urlString.matches("\\p{Graph}+\\.\\p{Alpha}{2,4}$");
Assuming that a file extension is a dot followed by 2, 3 or 4 alphabetic chars.
I am using a class that accepts overridden methods i meant optional argument signatures (not sure if that matters in this case, but maybe)
when I call this from IRB it is working as expected, eg, it accepts the arguments
(filtering namespaces and passwords with [filtered] where needed to keep secret stuff secret and my company happy)
jruby-1.5.0 > require 'java'
=> true
jruby-1.5.0 > Dir.glob('lib/java/*.jar').each{|jar| require jar}
=> ["lib/java/[filtered].jar", "lib/java/[filtered].jar", "lib/java/[filtered].jar"]
jruby-1.5.0 > import "[filtered].His351n1"
=> Java::[filtered]::His351n1
jruby-1.5.0 > broker = [filtered].Broker.new('[filtered]', '[filtered]')
=> #<Java::[filtered]::Broker:0x4c4936f3>
jruby-1.5.0 > rpc = "[filtered]"
=> "[filtered]"
jruby-1.5.0 > his = His351n1.new(broker, rpc)
=> #<Java::[filtered]::His351n1:0x7fb6a1c4>
and here is my spec and matching code
before(:each) do
#base = Legacy::Base.new
end
it "should create a valid his351n1 object" do
his = #base.create_his351n1
puts his.inpsect
end
# from within Legacy::Base
def create_his351n1
his = His351n1.new(build_broker, rpc)
end
and finally, the error which fails on the call to His351n1.new
1)
ArgumentError in 'Legacy::Base should create a valid his351n1 object'
wrong # of arguments(2 for 0)
To complicate things, on the irb, this is also apparently valid:
jruby-1.5.0 > his = His351n1.new
=> #<Java::[filtered]::His351n1:0x5ad3c69c>
Also, here are the overridden java methods
public His351n1() {
super();
}
public His351n1(Broker broker) {
this(broker, DEFAULT_SERVER);
}
public His351n1(BrokerService bs) {
this(bs.getBroker(), bs.toString());
}
public His351n1(Broker broker, String serverAddr) {
super(broker, serverAddr, "string", true);
}
public His351n1(final Broker broker, final String serverAddr, final String library)
{
super(broker, serverAddr, library, true);
}
it seems that you have to require the whole namespace in the instantiation of the object aka:
his = Java::[filtered_namesapce]::His351n1.new(build_broker, rpc)