cle_clock
Home > wikikonf >  was/actions/by kikonf > datasrc







Datasrc

print

Action : was.datasrc   (Category : was, Name : datasrc, By : kikonf)
Complete Name : was.datasrc.by.kikonf
Version : 5.0        License : Modified BSD License

Purpose of the was category :
Easy to customize. This category use in background the wsadmin command in jython mode (through AdminConfig, AdminControl and AdminTask), to drive WebSphere Application Server � configuration.
You can use it to manage the whole WebSphere � architecture.

Purpose of this datasrc plugin : Creates a new DataSource

The following shows the main Source Code File for the Action : was.datasrc

Toggle lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
##  Copyright (c) 2008, Patrick Germain Placidoux
##  All rights reserved.
##
##  This file is part of Kikonf Public Software.
##
##  Kikonf Public Software is released under the modified BSD License,
##  which should accompany it or any part of it in the file "COPYING".
##  If you do not have this file you can access the license
##
##  Contact: kikonf@gmx.com
 
 
 
 
from actions.was.tools import *
 
 
 
class Datasrc(wasAction):
     
    DATASRC=\
        {
            'db2': {
                'notxa':    'DB2 Universal JDBC Driver DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DB2_UNI_1)',
                'xa':       'DB2 Universal JDBC Driver XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DB2_UNI_2)',
            },
 
            'oracle_5': {
                'notxa':    'Oracle JDBC Driver DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_ora_5)',
            },
             
            'oracle_6': {
                'xa':    'Oracle JDBC Driver XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_ora_6)',
            },
             
            'msql': {
                'notxa':    'WebSphere embedded ConnectJDBC for SQL Server DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DD_3)',
                'xa':    'WebSphere embedded ConnectJDBC for SQL Server XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DD_4)',
            }
        }
 
    def extract(self, scope_attrs, name=None, prefix=None, doRaise=True, **keywords):
        self_funct='extract'
        from actions.was.jdbc.by.kikonf import jdbc
        self.verbose(scope_attrs, name=name, prefix=prefix)   
        scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent())
        indent=self.getIndent() + 3*' '
         
        verbose('DataSource retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ds=split( AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:/DataSource:/') )
        for d in ds: 
            datasrcs=getShowAsDict(AdminConfig.show(d))           
            dname=datasrcs['name']
             
            if not (prefix!=None and name!=None and dname==prefix + '_' + name \
            or prefix==None and name!=None and name==dname \
            or prefix!=None and name==None and dname.startswith(prefix) \
            or prefix==None and name==None):continue           
            verbose('DataSource:' + dname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
             
            if datasrcs.has_key('description') and datasrcs['description']!=None:desc=datasrcs['description']
            else:desc=None
            if desc==DESIGN_NOTICE:desc=None
             
            jndi_name=datasrcs['jndiName']
            provider=AdminConfig.showAttribute(datasrcs['provider'], 'name')
             
            try:
                ptype=jdbc.getProviderType(datasrcs['provider'], self)
                if ptype==None:raise
                if ptype.startswith('oracle'):ptype='oracle'
            except:
                verbose('DataSource:' + dname + ', not managed provider: ' + AdminConfig.showAttribute(datasrcs['provider'], 'name') + '. Skipped !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                continue
             
            verbose('JDBCProvider:' + provider + ' with type:' + ptype + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                 
            statement_cache_size=datasrcs['statementCacheSize']
             
            datasrc_node=self.newTop() #-- because in extract mode, each call returns a new blank top node.
            _name=dname
            if prefix!=None:_name=dname.split(prefix + '_')[1]
             
            datasrc_node.setAttrs(name=_name, desc=desc, jndi_name=jndi_name, provider=provider, dbtype=ptype, statement_cache_size=statement_cache_size, prefix=prefix)
             
            mkNodeScope(datasrc_node, scope_attrs, isUnique=True) #-- creates a scope node.
 
            jaas_name=datasrcs['authDataAlias']
            propset=datasrcs['propertySet']
             
            jaas=None
            verbose('JAASAuthData listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            as=split( AdminConfig.list("JAASAuthData") )
            for a in as:
                aname=AdminConfig.showAttribute(a, "alias")
                if jaas_name==aname:
                    jaas=a
                    break
                 
            if jaas==None:
                if doRaise:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, Unable to retreive JAAS Alias named:' + jaas_name + ' !')
                else:verbose('Tag: jaas, Unable to retreive JAAS Alias named:' + jaas_name + ' !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                user=password='?'
            else:
                user = AdminConfig.showAttribute(jaas, 'userId')
                verbose('JAASAuthData:' + aname + ' with user:' + user + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
 
                try:
                    password=self.getPwdFromJAAS(aname)
                except:password='???'
 
            _name=aname
            if prefix!=None:_name=aname.split(prefix + '_')[1]
             
            desc=AdminConfig.showAttribute(jaas, 'description')
            if desc!=None:desc=desc[1:-1]
            if desc==DESIGN_NOTICE:desc=None
             
            jaas_node=datasrc_node.newNode('jaas', name=_name, user=user, password=password, create='true', desc=desc)
              
            connection_pool_node=datasrc_node.newNode('connection_pool')        # Tag: connection_pool
            indent=self.getIndent() + 3*' '
            getConnectionPoolAttrs(datasrcs['connectionPool'], connection_pool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())
             
            rps = split( AdminConfig.showAttribute(datasrcs['propertySet'], 'resourceProperties') ) # Tag: properties
            properties_node=datasrc_node.newNode('properties')
 
            properties=jdbc.Jdbc.DRIVERS[ptype]['pset']
            for rp in rps:
                 
                for property in properties:
                    if rp.startswith(property):
                        value=AdminConfig.showAttribute(rp, 'value');
                        properties_node.newNode('property', name=property, value=value)
 
    def remove(self, no_name, no_name_no_prefix):
        datasrc_node=self.getTop()       
        datasrc_attrs = datasrc_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=datasrc_node, indent=self.getIndent()) #-- Retreives scope
        self.verbose(scope_attrs, name=datasrc_attrs.name, prefix=datasrc_attrs.prefix)
        indent=self.getIndent() + 3*' '
 
        # no_name/no_name_no_prefix
        prefix=datasrc_attrs.prefix
        name=datasrc_attrs.name
        if no_name or no_name_no_prefix:name=None
        if no_name_no_prefix:prefix=None
         
        # remove all at prefix if present.
        self.rmvDatasrc(name=name, prefix=prefix, indent=indent)
         
        if datasrc_node.hasNode('jaas'):
            jaas_node=datasrc_node.getNode('jaas')[0]
            jaas_attrs = jaas_node.getAttrs()       
            if jaas_attrs.create == 'true':self.rmvJaas(name=jaas_attrs.name, prefix=datasrc_attrs.prefix, indent=indent) # not allowed to destroy all.
     
    def inject(self):
        self_funct='inject'
        datasrc_node = self.getTop()       
        datasrc_attrs = datasrc_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=datasrc_node, indent=self.getIndent()) #-- Retreives scope
        from actions.was.jdbc.by.kikonf import jdbc
        indent=self.getIndent() + 3*' '
         
        self.rmvDatasrc(name=datasrc_attrs.name, prefix=datasrc_attrs.prefix, indent=indent) #-- Destroy all first       
 
        #-- name
        if datasrc_attrs.prefix==None:name=datasrc_attrs.name
        else:name=datasrc_attrs.prefix + '_' + datasrc_attrs.name
        self.verbose(scope_attrs, name=name, prefix=datasrc_attrs.prefix)
 
        if datasrc_node.hasNode('jaas'):
            jaas_node=datasrc_node.getNode('jaas')[0]
            jaas_attrs = jaas_node.getAttrs()
            jaas_name=self.inJaas(jaas_attrs, datasrc_attrs.prefix, indent=indent)
        else:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, is required !')
         
        verbose('JDBCProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        provider = AdminConfig.getid(self.getScopeCP()+'/JDBCProvider:' + datasrc_attrs.provider)
 
        if provider in ('', None):raise xception.kikonfActionSystemException(self, self_funct, 'Unable to retreive provider:' + datasrc_attrs.provider +  '!')
        verbose('JDBCProvider:' + provider + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
 
        dbtype=datasrc_attrs.dbtype
        if AdminConfig.showAttribute(provider, 'xa')=='true':
            isxa='xa'
            if dbtype=='oracle':dbtype+='_6'
        else:
            isxa='notxa'       
            if dbtype=='oracle':dbtype+='_5'
        if not Datasrc.DATASRC[dbtype].has_key(isxa):raise xception.kikonfActionSystemException(self, self_funct, 'This dbtype:' + datasrc_attrs.dbtype + 'do not support  this xa mode:' + iswa + ' !')       
        dtmpl=Datasrc.DATASRC[dbtype][isxa]     
 
        cmdvalues=[]
        cmdvalues.append(['name', name])
        cmdvalues.append(['jndiName', datasrc_attrs.jndi_name])
         
        if datasrc_attrs.desc!=None:cmdvalues.append(['description', datasrc_attrs.desc])
        else:cmdvalues.append(['description', DESIGN_NOTICE])
         
        cmdvalues.append(['authDataAlias', jaas_name])
        cmdvalues.append(['statementCacheSize', datasrc_attrs.statement_cache_size])
 
        if datasrc_node.hasNode('connection_pool'):
            conpool_node=datasrc_node.getNode('connection_pool')[0]
            cmdvalues.append(['connectionPool', getConnectionPoolCfgs(conpool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())])
 
        if isxa=='xa':cmdvalues.append(['xaRecoveryAuthAlias', jaas_name])
         
        # creates
        verbose('DataSource template listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        verbose('DataSource' + datasrc_attrs.name + ' creating using template.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ds = AdminConfig.createUsingTemplate('DataSource', provider, 'name', datasrc_attrs.name, dtmpl)
        AdminConfig.modify(ds, cmdvalues)
        verbose('DataSource:' + datasrc_attrs.name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                  
        if datasrc_node.hasNode('properties'):self.inProps(datasrc_node.getNode('properties')[0], datasrc_attrs.provider, name, indent=indent + 3*' ')
  
    def rmvDatasrc(self, name=None, prefix=None, indent=None):
        scope_id, scope_attrs, scope=self.getScope()
        verbose('DataSource listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ds=getStartByNameAsDict(split( AdminConfig.list('DataSource', scope_id) ))
     
        for dname in ds.keys():
            if prefix!=None and dname.startswith(prefix) \
            or prefix==None and name!=None and name==dname \
            or prefix==None and name==None:
             
                verbose('DataSource:' + dname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(ds[dname])
                verbose('DataSource:' + dname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                     
    def inJaas(self, jaas_attrs, prefix=None, indent=None):
        self_funct='inJaas'
        if prefix==None:name=jaas_attrs.name
        else:name=prefix + '_' + jaas_attrs.name
        if jaas_attrs.create == 'false':return name
        self.rmvJaas(name=jaas_attrs.name, prefix=prefix, indent=indent)
         
        if jaas_attrs.user==None or jaas_attrs.password==None:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, because Attribute "create" is false, Attributes user and password must be guiven !')
        cmdvalues=[]
         
        cmdvalues.append(['alias', name])
         
        if jaas_attrs.desc!=None:description=['description', jaas_attrs.desc]
        else:description=['description', DESIGN_NOTICE]
         
        cmdvalues.append(['userId', jaas_attrs.user])
        cmdvalues.append(['password', jaas_attrs.password])
 
        verbose('Security retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        security = AdminConfig.getid('/Cell:' + self.getCell() + '/Security:/')
        verbose('JAASAuthData:' + name + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        jaasAlias = AdminConfig.create('JAASAuthData', security, cmdvalues)
        verbose('JAASAuthData:' + name + ' with name:' + jaas_attrs.user + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
         
        return name
         
    def rmvJaas(self, name=None, prefix=None, indent=None):
        verbose('JAASAuthData listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        as=split(AdminConfig.list("JAASAuthData"))
         
        for a in as:
            aname=AdminConfig.showAttribute(a, "alias")
 
            if prefix!=None and aname.startswith(prefix) \
            or prefix==None and name!=None and name==aname:
            # or prefix==None and name==None: not allowed to destroy all
             
                verbose('JAASAuthData:' + aname  + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(a)
                verbose('JAASAuthData:' + aname  + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
             
    def inProps(self, node, provider, datasrc, indent=None):
        props={}
         
        for prop_node in node.getNodes():
            dct=prop_node.getdAttrs()
            props[dct['name']]=dct['value']
  
        if len(props)!=0:
            self.rmvProps(provider, datasrc, upds=props.keys(), indent=indent) #-- destroy first
     
            verbose('JDBCProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            pset=AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:' + provider + '/DataSource:' + datasrc + '/J2EEResourcePropertySet:/')       
            for prop in props.keys():
                verbose('J2EEResourceProperty:' + prop + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.create('J2EEResourceProperty', pset, [['name', prop],['value', props[prop]]])
                verbose('J2EEResourceProperty:' + prop + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
         
    def rmvProps(self, provider, datasrc, upds=None, indent=None):
        if upds==None:return
         
        verbose('J2EEResourceProperty retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ps = getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:' + provider + '/DataSource:' + datasrc + '/J2EEResourcePropertySet:/J2EEResourceProperty:/') ))
 
        for pname in ps.keys():
            if pname in upds:
                 
                verbose('J2EEResourceProperty:' + pname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(ps[pname])
                verbose('J2EEResourceProperty:' + pname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
 
    def verbose(self, scope_attrs, name=None, prefix=None):
        scope=str(scope_attrs).replace("'", '')[1:-1]
         
        if name!=None and prefix!=None:verbose('DataSource:' + name + ', under prefix:' + prefix+ ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif name!=None:verbose('DataSource:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif prefix!=None:verbose('DataSources under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        else:verbose('DataSources at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
                            
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/datasrc/by/kikonf/datasrc.py)


  • Line 1 to 3 say something , say something , say something
  • Line 10 to 17 say something , say something , say something , say something , say something
  • Line 20 to 25 say something



Trademarks :
  • "Python" is a registered trademark of the Python Software Foundation.
  • "IBM", "WebSphere MQ", "WebSphere", "WebSphere Aplication Server", "WAS", "Db2" and "AIX" are registred trademarks of International Business Machines Corporation.
  • "oracle", "MySql", "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • "Linux" is a trademark registred to Linus Torvalds
  • "MS SQL Server" is a registred trademark of Microsoft Corporation.
  • "IBM", "WebSphere", "WebSphere Aplication Server", "WAS" are registred trademarks of International Business Machines Corporation.
  • "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • Other names may be trademarks of their respective owners.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud