We have a custom weblogic template which has admin server (obviously) and a cluster with 2 managed servers deployed to the same machine. We use that template for our development environments. But now when we move on to performance testing environments, we need to introduce more machines.
It's easy to create a new machine in WLST (offline or online mode). But how do I clone a server (as all of the settings, except weblogic.Name and target machine are the same) in WLST?
It seems to be possible in WebLogic Administration Console, but we need to automate that.
I ended up doing defining the following functions:
def createServer(wls, name):
wls.cd("/")
wls.create(name, 'Server')
######################################################################
# Checks if given bean exists
######################################################################
def beanExists(wls, path, name):
print "Checking if bean: '" + name + "' exists in path: '" + path + "'"
wls.cd(path)
wls.setShowLSResult(0)
beans = wls.ls('c', 'false', 'c')
wls.setShowLSResult(1)
if (beans.find(name) != -1):
print "Exists"
return 1
else:
print "Doesn't exist"
return 0
######################################################################
# Copy bean properties in offline mode.
######################################################################
def copyProperties(wls, originalBeanName, originalBeanPath, newBeanName, newBeanPath, ignoredProperties):
wls.getCommandExceptionHandler().setMode(1)
wls.getRuntimeEnv().set('exitonerror', 'true')
srcPath = originalBeanPath + "/" + originalBeanName
targetPath = newBeanPath + "/" + newBeanName
print "Coping properties from '" + srcPath + "' to '" + targetPath + "'"
wls.cd(srcPath)
wls.setShowLSResult(0)
attributes = wls.ls('a', 'true', 'a')
children = wls.ls('c', 'true', 'c')
wls.setShowLSResult(1)
# Copy attributes.
wls.cd(targetPath)
for entry in attributes.entrySet():
k = entry.key
v = entry.value
if not(k in ignoredProperties) and not(v is None) and not(v == ''):
print "Setting property '" + str(k) + "' = '" + str(v) + "' on '" + targetPath + "'"
if isinstance(v, StringType):
wls.set(k, v.replace(originalBeanName, newBeanName))
else:
wls.set(k, v)
# Copy child bean values.
for k in children:
if not(k in ignoredProperties):
srcBN = srcPath + "/" + k
targetBN = targetPath + "/" + k
print "Coping bean '" + srcBN + "/" + originalBeanName + "'"
print "Detected bean type as '" + k + "'"
if beanExists(wls, srcBN, "NO_NAME_0"):
print "Changing to NO_NAME_0"
originalBeanName = "NO_NAME_0"
newBeanName = "NO_NAME_0"
wls.cd(targetPath)
wls.create(newBeanName, k)
copyProperties(wls, originalBeanName, srcBN, newBeanName, targetBN, ignoredProperties)
After that just call:
createServer(WLS, 'ServiceServer3')
copyProperties(WLS, 'ServiceServer1', '/Servers', 'ServiceServer3', '/Servers', ['SSL'])
UPDATE: I wrote more about it in my blog: http://blog.aestasit.com/cloning-objects-in-wlst-offline/. Also the script was tested on WebLogic 11g.
I'm not sure about the newest version of WLST but the older releases don't have a single command for it since clone is on the console side - It's not a functionality that can be invoked on an MBean.
You could write a script that takes a serverName as a parameter, traverses through all resources and then creates your new server. Alternatively, Oracle's OEM could be used as well. Hope that helps.
Related
This question already has answers here:
VBA Function Avoiding If Statements
(3 answers)
Closed 2 years ago.
How to do this without hardcoding every Jar version?
So, in every ElseIf, it checks the version, if it's (for example 1.2.5), then download the software accordingly, to the path selected by the user + \ + type + _ + version + .jar. The problem is that there are more versions (more than 30 I think) and I don't want to hardcode all of them.
If JarVer = "1.2.1" Or JarVer = "1.2.2" Or JarVer = "1.2.3" Or JarVer = "1.2.4" Then
My.Computer.Network.DownloadFile(
"https://assets.minecraft.net/1_2/minecraft_server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.2.5" Then
My.Computer.Network.DownloadFile(
"https://assets.minecraft.net/1_2_5/minecraft_server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.3.1" Then
My.Computer.Network.DownloadFile(
"https://launcher.mojang.com/v1/objects/d8321edc9470e56b8ad5c67bbd16beba25843336/server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.3.2" Then
My.Computer.Network.DownloadFile(
"https://launcher.mojang.com/v1/objects/82563ce498bfc1fc8a2cb5bf236f7da86a390646/server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.4.2" Then
My.Computer.Network.DownloadFile(
"https://launcher.mojang.com/v1/objects/3de2ae6c488135596e073a9589842800c9f53bfe/server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
...
They have to be hardcoded somewhere unless you have a consistent pattern.
I would consider putting the list in a data table or dictionary, then looking up the url from the version.
I have loaded the variables in the format for example:
where produkt = 'Muj zivot2 R' and uraz = 'Uraz'
and I need the output in the file name to be:
Muj zivot2 R_Uraz
token worked for me, but it doesn't work in this case
" + TOKEN(" #[User::where] ","''",2) + "_" + TOKEN(" #[User::where] ","''",4) + "
You can use the following expression:
TOKEN(#[User::where],"'",2) + "_" + TOKEN(#[User::where],"'",4)
Output
Muj zivot2 R_Uraz
When my query executes within my VB application I am receiving the following error:
ORA-00942: table or view does not exist
All table names in my query are spelt correctly, and do in fact exist.
If I dump the query from my VB.net app and then run the query manually in Oracle SQL Plus it executes just fine.
In both cases I am logged in with the exact same credentials and have selected the same database. For my connection within visual basic I am using OleDb.
From within my visual basic application I also ran a query to dump all tables which the user has access to using
select table_name from all_tables
And the table names which I am querying show up.
Any idea what would be causing this?
SELECT
RSS.STEP_STATUS_DATE,
RSS.VALUE_RECORDED
FROM
ITR,
REPORT R,
INSTRUCTION I,
INSTRUCTION_STEP INS,
REPORT_STEP RS,
REPORT_STEP_STATUS RSS
WHERE
ITR.ITR_NO = '1' AND
I.INSTRUCTION_ID = '12345' AND
INS.STEP_NO = '2' AND
R.INSTRUCTION_ID = I.INSTRUCTION_ID AND
RS.REPORT_ID = R.REPORT_ID AND
RS.INSTRUCTION_STEP_ID = INS.INSTRUCTION_STEP_ID AND
RSS.REPORT_STEP_ID = RS.REPORT_STEP_ID AND
RSS.MEASUREMENT_NAME = 'ESN'
My visual basic code is as follows:
strQuery = "SELECT RSS.STEP_STATUS_DATE, " +
" RSS.VALUE_RECORDED " +
"FROM ITR, " +
" REPORT R, " +
" INSTRUCTION I, " +
" INSTRUCTION_STEP INS, " +
" REPORT_STEP RS, " +
" REPORT_STEP_STATUS RSS " +
"WHERE ITR.ITR_NO = '%01' AND " +
" I.INSTRUCTION_ID = '%02' AND " +
" INS.STEP_NO = '%03' AND " +
" R.INSTRUCTION_ID = I.INSTRUCTION_ID AND " +
" RS.REPORT_ID = R.REPORT_ID AND " +
" RS.INSTRUCTION_STEP_ID = INS.INSTRUCTION_STEP_ID AND " +
" RSS.REPORT_STEP_ID = RS.REPORT_STEP_ID AND " +
" RSS.MEASUREMENT_NAME = '%04'"
I'm looking at this portion (and others like it):
RSS.MEASUREMENT_NAME = '%04'
I expect you meant to do this:
RSS.MEASUREMENT_NAME LIKE '%04'
While I'm here, almost no one uses the "A,B" join syntax any more. It's extremely out-dated, and can lead to errors where join conditions are applied to the wrong tables, such that the query doesn't return any results... in other words, it might even be causing the problem you have right now.
I am trying to run this Query in my VB Application but receive an error saying:
unable to cast object of type 'system.string' to type 'system.iformatprovider'
SQL = "insert into billing_pdf_archive (reseller_sequence, invoice_number, pdf, worddoc, csv_cdr_file, csv_services_file, sub_total, vat_amount, grand_total, invoice_type, directdebit) values ('" + reseller.ToString + "','" + invoice_number.ToString + "', '" + Replace(reseller_company_name + "-" + invoice_number + ".pdf", " ", "_") + "', '" + Replace(reseller_company_name + "-" + invoice_number + ".doc", " ", "_") + "', '" + Replace(reseller_company_name + "-" + invoice_number.ToString + "_CDR.xlsx", " ", "_") + "', '" + Replace(reseller_company_name + "-" + invoice_number.ToString + "_Services.xlsx", " ", "_") + "', " + total.ToString("F2") + ", " + vat_amount.ToString("F2") + ", " + grand_total.ToString("F2") + ", 'Month End Reseller', '" + customer_direct_debit + "')"
conn3.ConnectionString = "server=" + global_variables.web_server_ip + "; user id=" + global_variables.web_server_username + "; password=" + global_variables.web_server_password + "; database=" + global_variables.web_server_database + "; "
conn3.Open()
myCommand3.Connection = conn3
myCommand3.CommandText = SQL
myCommand3.ExecuteNonQuery()
conn3.Close()
This is not a complete answer but I'll post it as an answer so that I can post formatted code. If you do as suggested in the comments and write clean, readable code then it will become obvious where the issue is and how to fix it. When you have one line that does lots of different things then working out what on that line is causing an issue is all but impossible. You should use an XML literal for your SQL code, parameters for your values and a connection string builder, e.g.
Dim sql = <sql>
INSERT INTO MyTable
(
Column1,
Column2
)
VALUES
(
#Column1,
#Column2
)
</sql>
command.CommandText = sql.Value
command.Parameters.AddWithValue("#Column1", value1)
command.Parameters.AddWithValue("#Column2", value2)
Dim builder As New SqlConnectionStringBuilder
builder.DataSource = server
builder.InitialCatalog = database
connection.ConnectionString = builder.ConnectionString
Now you'll be able to see exactly what part of your code is causing the issue and, if you still can't solve it yourself, will be able to point out where the issue is to us instead of expecting us to read that dog's breakfast.
I Work on C# Project (WinForm)
I Install Sql Server 2008 Express On Client PC.
in Start Of My Program Must Create a Database. So I Use This Code For Create a Database:
string sqlCreateDBQuery;
SqlConnection tmpConn = new SqlConnection(#"SERVER =.\SQLEXPRESS; Trusted_Connection = yes;DATABASE = master;");
sqlCreateDBQuery = " CREATE DATABASE "
+ DatabaseName
+ " ON PRIMARY "
+ " (NAME = " + DatabaseName + ", "
+ " FILENAME = '" + #"C:" + #"\" + DatabaseName + ".mdf" + "', "
+ " SIZE = 3MB,"
+ " FILEGROWTH = " + "10%" + ") "
+ " LOG ON (NAME =" + "MyDatabase_Log" + ", "
+ " FILENAME = '" + #"C:" + #"\" + DatabaseName + "_log.ldf" + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH = " + "10%" + ") ";
sqlCreateDBQuery = Coomand;
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox.Show(sqlCreateDBQuery);
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
tmpConn.Close();
}
return;
But When My Program Run I See Following Error
What is My Problem?
It looks from the error message that you don't have permissions to create your mdf file on the root. Truth be told, you should not have put it there anyway, as that is much too exposed. Put it in your application's folder, or somewhere obscure where it won't be accidentally deleted.
I also think that you should be running this as a install script for the initial setup, rather than in your code. I am a big proponent of keeping sql out of code as much as possible, but to each his own. You say you set up the SQL Server DB, you should use the tools at your disposal to make this easy for you. I had a book from Wrox that served me well, here is the link: http://www.wrox.com/WileyCDA/WroxTitle/Wrox-s-SQL-Server-2005-Express-Edition-Starter-Kit.productCd-0764589237.html -Amazon has it for $2 - http://www.amazon.com/Server-Express-Edition-Starter-Programmer/dp/B006TQYC8U/ref=sr_1_1?ie=UTF8&qid=1342019983&sr=8-1&keywords=Wrox%27s+SQL+Server+2005+Express+Edition+Starter+Kit
Also:
http://msdn.microsoft.com/en-us/library/bb264562(v=sql.90).aspx