How to changing WebSphere Application Server datasource URL by wsadmin? - websphere

Is possible to change Websphere datasource IP address? I've tried this script but it doesn't work
def updateDataSourceIP(newIP):
datasources = AdminConfig.getid('/DataSource:/').splitlines()
for datasource in datasources:
propertySet = AdminConfig.showAttribute(t1, 'propertySet')
propertyList = AdminConfig.list('J2EEResourceProperty', propertySet).splitlines()
for prop in propertyList:
if (AdminConfig.showAttribute(prop, 'name') == 'serverName'):
oldip = AdminConfig.showAttribute(prop, 'value')
print "Updating serverName attribute of datasource '" + datasource + "' from " + oldip + " to " + sys.argv[0]
AdminConfig.modify(prop, '[[value ' + newIP + ']]')
AdminConfig.reset();

In your example code, you are using
AdminConfig.reset()
at the end of the script, which discards all changes. Try switching to
AdminConfig.save()

Related

How do I get the get list of connections from processContext in NiFi 1.11.4

Our production instance of NiFi is version 1.8.0. We have a custom processor that continually looks at it's downstream connections in order to route flow files based on the connection's queue size.
Here is the salient snippet of how we do this . . .
String processorId = this.getIdentifier();
ProcessorGroupStatus processGroupStatus = ((EventAccess) getControllerService()).getContollerStatus();
Collection<ConnectionStatus> groupConnections = processGroupStatus.getConnectionStatus();
ArrayList connections = new ArrayList<>(groupConnections);
for (Object processorConnection : connections) {
ConnectionStatus connection = (ConnectionStatus) processorConnection;
if(connection.getSourceId().equals(processorId){
//do stuff with connection.getQueuedCount() & connection.getQueuedBytes()
break;
}
}
Everything has been working as expected for the last couple of years. However, upgrading our NiFi instance to version 1.11.4 has broken this approach. The exception thrown is:
class org.apache.nifi.contoller.serviceStandardContollerServiceProvider cannot be cast to class org.apache.nifi.reporting.EventAccess
Is there another way to retrieve connections from processContext?
One approach that may be more upwardly compatible (and easier to maintain) than a custom Java processor would be to use the ExecuteGroovyScript processor.
The Groovy script in this case would look something like:
ff = session.get()
if (ff) {
me = context.procNode
processorId = me.identifier
connections = me.processGroup.connections
connections.each { connection ->
if(connection.source.identifier.equals(processorId)) {
ff[connection.identifier] = "I am the source " +
"[" + connection.flowFileQueue.size().objectCount + "]" +
"[" + connection.flowFileQueue.size().byteCount + "]"
}
else {
ff[connection.identifier] = "I am NOT the source; my name is [" + connection.name + "]"
}
}
REL_SUCCESS << ff
}
To find out what is available to the Groovy script, I use a combination of the NiFi JavaDocs (https://javadoc.io/static/org.apache.nifi/nifi-api/1.12.0/index.html) and the Github code for NiFi (https://github.com/apache/nifi/tree/c396927299586b896df4ebc745793b4c451f3898/nifi-api/src/main/java/org/apache/nifi).
As a side note, we converted our custom Java processors to Groovy script, because of an upgrade incompatibility when going to (ironically) 1.8.0. We have not had an issue with NiFi upgrades since then, and are currently running v 1.11.4.

Airflow UI link in SlackAPIPostOperator?

Im using SlackAPIPostOperator in Airflow to send Slack messages on task failures.
I wondered if there's a smart way to add a link to the airflow UI logs page of the failed task to the slack message.
The following is an example I want to achieve:
http://myserver-uw1.myaws.com:8080/admin/airflow/graph?execution_date=...&arrange=LR&root=&dag_id=MyDAG&_csrf_token=mytoken
The current message is:
def slack_failed_task(context):
failed_alert = SlackAPIPostOperator(
task_id='slack_failed',
channel="#mychannel",
token="...",
text=':red_circle: Failure on: ' +
str(context['dag']) +
'\nRun ID: ' + str(context['run_id']) +
'\nTask: ' + str(context['task_instance']))
return failed_alert.execute(context=context)
You can build the url to the UI with the config value base_url under the [webserver] section and then use Slack's message format <http://example.com|stuff> for links.
from airflow import configuration
def slack_failed_task(context):
link = '<{base_url}/admin/airflow/log?dag_id={dag_id}&task_id={task_id}&execution_date={execution_date}|logs>'.format(
base_url=configuration.get('webserver', 'BASE_URL'),
dag_id=context['dag'].dag_id,
task_id=context['task_instance'].task_id,
execution_date=context['ts'])) # equal to context['execution_date'].isoformat())
failed_alert = SlackAPIPostOperator(
task_id='slack_failed',
channel="#mychannel",
token="...",
text=':red_circle: Failure on: ' +
str(context['dag']) +
'\nRun ID: ' + str(context['run_id']) +
'\nTask: ' + str(context['task_instance']) +
'\nSee ' + link + ' to debug')
return failed_alert.execute(context=context)
We can also do this using the log_url attribute in the Task Instance
def slack_failed_task(context):
failed_alert = SlackAPIPostOperator(
task_id='slack_failed',
channel="#mychannel",
token="...",
text=':red_circle: Failure on: ' +
str(context['dag']) +
'\nRun ID: ' + str(context['run_id']) +
'\nTask: ' + str(context['task_instance']) +
'\nLogs: <{url}|to Airflow UI>'.format(url=context['task_instance'].log_url)
)
return failed_alert.execute(context=context)
I know this is available since version 1.10.4 at the very least.

Changing container managed authentification alias

I'm using WebSphere 7.0.0.37 and jython
I need to change the 'Container-managed authentication alias', unfortunatelly I can't find anything in API, inspecting attributes of existing DataSources or any example for that task.
I have succesfully changed the 'composant-managed authentication alias' with:
AdminConfig.modify(DataSourceProvider, '[[name "basename"] [authDataAlias "' + nameNode + '/' + aliasJaas + '" ] ')
How can i do that?
thank you!
Here is some logic which you could use to solve your problem.
# Create new alias
cellName = AdminConfig.showAttribute(AdminConfig.list("Cell"), "name")
security = AdminConfig.getid('/Cell:' + cellName + '/Security:/')
myAlias = 'blahAlias'
user = 'blah'
pswd = 'blah'
jaasAttrs = [['alias', myAlias], ['userId', user], ['password', pswd ]]
print AdminConfig.create('JAASAuthData', security, jaasAttrs)
print "Alias = " + myAlias + " was created."
# Get a reference to your DataSource (assume you know how to do this):
myDS = ...
# Set new alias on DataSource
AdminConfig.modify('MappingModule', myDS, '[[authDataAlias ' + myAlias + '] [mappingConfigAlias DefaultPrincipalMapping]]')
Note that if you can figure out how to do a given task in the Admin Console, you can use the "Command Assist" function to get a Jython snippet to do the equivalent via wsadmin. See here.

Jython with wsadmin: WASX7017E com.ibm.ws.scripting.ScriptingException: Invalid object name

I have a Jython script calling wsadmin libraries to configure a WAS server.
I have these functions:
def createWasObject(was_object_type, was_path, object_params):
if isinstance(was_path, basestring):
was_path = AdminConfig.getid(was_path)
str_params = '['
for k,v in object_params.items():
str_params = str_params + '[' + k + ' "' + v + '"] '
str_params = str_params + ']'
return AdminConfig.create(was_object_type, was_path, str_params)
def createJdbcProviders(was_path, jdbc_providers):
was_object_type = 'JDBCProvider'
for jdbc_provider in jdbc_providers:
jdbc = createWasObject(was_object_type, was_path, jdbc_provider['params'])
print jdbc
for datasource in jdbc_provider['datasources']:
ds = createWasObject('Datasource', jdbc, datasource['params'])
print
The "print jdbc" prints:
Teradata JDBC Provider(cells/jsr-websphere-1Cell01/nodes/jsr-websphere-1Node01/servers/jsr-business|resources.xml#JDBCProvider_1444648929602)"
Which looks like a correct object ID
However, when using it to create a datasource, I get the following error:
WASX7017E: Exception reçue lors de l'exécution du fichier "/root/jsr_auto_deployment/jsr.py" ; informations sur l'exception : com.ibm.ws.scripting.ScriptingException: Invalid object name: "Teradata JDBC Provider(cells/jsr-websphere-1Cell01/nodes/jsr-websphere-1Node01/servers/jsr-business|resources.xml#JDBCProvider_1444648929602)"
I am using Jython 2.7 through a Thin client. Reusing an object returned by AdminConfig.create() was working well with a Jython script ran through wsadmin.sh
My problem was on that line:
was_path = AdminConfig.getid(was_path)
Most of the time I was passing a string but this time I was already using an ID. So I removed the AdminConfig.getid in the function and added it in the calls when necessary only.

Server Not Found Exception in wsadmin

I have a jython script to create a server, deploy and application and then start the server.
But I am geeting the following exception while running it.
WASX7017E: Exception received while running file "myfile.py"; exception information: javax.management.MBeanException[[ com.ibm.websphere.management.exception.AdminException: Server, SERVERNAME, not found.
Here is the entire code... http://snipt.org/BMaf4
Update: He is the entire log http://snipt.org/BNZ1
Can't figure out where I am going wrong.
But When I am issuing a start all servers in wsadminlib.. the server gets started
The problem might be in the way how you deploying and/or configuring your application.
# Your script sample
# Deploy the WAR
APP_PATH= APP_HOME + '/MYAPP/CycleWAR/war/MYAPPCycle.war'
ARGS_LIST='.....'
AdminApp.install(APP_PATH, ARGS_LIST)
You need to add another parameter into your arguments list ARGS_LIST : args = "[-server " + SERVER_NAME + "]"
# Since 6.0.X version
# Server Deployment
args = "[-server " + serverName + "]"
# Cluster Deployment
# args = "[-cluster " + clusterName + "]"
AdminApp.install(applicationFilePath, args)
After the server configurations...
#Sync the Nodes
Sync1 = AdminControl.completeObjectName( "type=NodeSync,node="+ NODE_NAME +",*")
print "Getting Sync Info.. " + "\n" + Sync1
AdminControl.invoke(Sync1, 'sync')
print NODE_NAME + " Sync Completed.. "
We have to sync the nodes first before trying to start the server.

Resources