from
actions.was.tools
import
*
class
Cache(wasAction):
def
extract(
self
, scope_attrs
=
None
, name
=
None
, prefix
=
None
,
*
*
keywords):
self_funct
=
'extract'
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(
'ObjectCacheInstance listing.'
, level
=
self
.getVerbose(), ifLevel
=
4
, indent
=
indent, logFile
=
self
.getLogFile())
cs
=
getStartByNameAsDict(split(AdminConfig.
list
(
'ObjectCacheInstance'
, scope_id)))
verbose(
'ObjectCacheInstances listed.'
, level
=
self
.getVerbose(), ifLevel
=
3
, indent
=
indent, logFile
=
self
.getLogFile())
for
cname
in
cs.keys():
if
prefix!
=
None
and
name!
=
None
and
cname
=
=
prefix
+
'_'
+
name \
or
prefix
=
=
None
and
name!
=
None
and
cname
=
=
name \
or
prefix!
=
None
and
name
=
=
None
and
cname.startswith(prefix) \
or
prefix
=
=
None
and
name
=
=
None
:
verbose(
'Found matching ObjectCacheInstance:'
+
cname
+
'.'
, level
=
self
.getVerbose(), ifLevel
=
3
, indent
=
indent, logFile
=
self
.getLogFile())
cache_node
=
self
.newTop()
caches
=
getShowAsDict(AdminConfig.show(cs[cname]))
_name
=
cname
if
prefix!
=
None
:_name
=
cname.split(prefix
+
'_'
)[
1
]
desc
=
None
if
caches.has_key(
'description'
)
and
caches[
'description'
]!
=
None
:desc
=
caches[
'description'
][
1
:
-
1
]
if
desc
=
=
DESIGN_NOTICE:desc
=
None
cache_node.setAttrs(name
=
_name, jndi_name
=
caches[
'jndiName'
], size
=
caches[
'cacheSize'
], desc
=
desc, prefix
=
prefix)
mkNodeScope(cache_node, scope_attrs, isUnique
=
True
)
def
remove(
self
, no_name, no_name_no_prefix):
cache_node
=
self
.getTop()
cache_attrs
=
cache_node.getAttrs()
scope_id, scope_attrs, scope
=
self
.getScope(parent_node
=
cache_node, indent
=
self
.getIndent())
prefix
=
cache_attrs.prefix
name
=
cache_attrs.name
if
no_name
or
no_name_no_prefix:name
=
None
if
no_name_no_prefix:prefix
=
None
self
.verbose(scope_attrs, name
=
name, prefix
=
prefix)
indent
=
self
.getIndent()
+
3
*
' '
self
.rmvCache(name
=
name, prefix
=
prefix, indent
=
indent)
def
inject(
self
):
self_funct
=
'inject'
cache_node
=
self
.getTop()
cache_attrs
=
cache_node.getAttrs()
scope_id, scope_attrs, scope
=
self
.getScope(parent_node
=
cache_node, indent
=
self
.getIndent())
self
.verbose(scope_attrs, name
=
cache_attrs.name, prefix
=
cache_attrs.prefix)
indent
=
self
.getIndent()
+
3
*
' '
self
.rmvCache(name
=
cache_attrs.name, prefix
=
cache_attrs.prefix, indent
=
indent)
if
cache_attrs.prefix
=
=
None
:name
=
cache_attrs.name
else
:name
=
cache_attrs.prefix
+
'_'
+
cache_attrs.name
if
cache_attrs.desc
=
=
None
:desc
=
DESIGN_NOTICE
else
:desc
=
cache_attrs.desc
cmdvalues
=
[]
cmdvalues.append([
'name'
, name])
cmdvalues.append([
'jndiName'
, cache_attrs.jndi_name])
cmdvalues.append([
'cacheSize'
, cache_attrs.size])
cmdvalues.append([
'defaultPriority'
,
1
])
cmdvalues.append([
'enableDiskOffload'
,
'false'
])
cmdvalues.append([
'flushToDiskOnStop'
,
'false'
])
cmdvalues.append([
'useListenerContext'
,
'false'
])
cmdvalues.append([
'disableDependencyId'
,
'false'
])
cmdvalues.append([
'description'
, desc])
verbose(
'ObjectCacheInstance retreiving.'
, level
=
self
.getVerbose(), ifLevel
=
4
, indent
=
indent, logFile
=
self
.getLogFile())
wpv
=
AdminConfig.getid(scope.getCP()
+
'/CacheProvider:/'
)
AdminConfig.create(
'ObjectCacheInstance'
, wpv, cmdvalues)
verbose(
'ObjectCacheInstance:'
+
name
+
' created.'
, level
=
self
.getVerbose(), ifLevel
=
3
, indent
=
indent, logFile
=
self
.getLogFile())
def
rmvCache(
self
, name
=
None
, prefix
=
None
, indent
=
None
):
scope_id, scope_attrs, scope
=
self
.getScope()
verbose(
'ObjectCacheInstance listing.'
, level
=
self
.getVerbose(), ifLevel
=
4
, indent
=
indent, logFile
=
self
.getLogFile())
cs
=
getStartByNameAsDict(split(AdminConfig.
list
(
'ObjectCacheInstance'
, scope_id)))
verbose(
'ObjectCacheInstances listed.'
, level
=
self
.getVerbose(), ifLevel
=
3
, indent
=
indent, logFile
=
self
.getLogFile())
for
cname
in
cs.keys():
if
cname
=
=
'':
continue
if
prefix!
=
None
and
cname.startswith(prefix) \
or
prefix
=
=
None
and
name!
=
None
and
name
=
=
cname \
or
prefix
=
=
None
and
name
=
=
None
:
verbose(
'ObjectCacheInstance:'
+
cname
+
' removing.'
, level
=
self
.getVerbose(), ifLevel
=
4
, indent
=
indent, logFile
=
self
.getLogFile())
AdminConfig.remove(cs[cname])
verbose(
'ObjectCacheInstance:'
+
cname
+
' 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(
'ObjectCacheInstance:'
+
name
+
', under prefix:'
+
prefix
+
', at scope:'
+
scope
+
'.'
, level
=
self
.getVerbose(), ifLevel
=
2
, indent
=
self
.getIndent(), logFile
=
self
.getLogFile())
elif
name!
=
None
and
prefix
=
=
None
:verbose(
'ObjectCacheInstance:'
+
name
+
', at scope:'
+
scope
+
'.'
, level
=
self
.getVerbose(), ifLevel
=
2
, indent
=
self
.getIndent(), logFile
=
self
.getLogFile())
elif
prefix!
=
None
:verbose(
'ObjectCacheInstances under prefix:'
+
prefix
+
', at scope:'
+
scope
+
'.'
, level
=
self
.getVerbose(), ifLevel
=
2
, indent
=
self
.getIndent(), logFile
=
self
.getLogFile())
else
:verbose(
'ObjectCacheInstances at scope:'
+
scope
+
'.'
, level
=
self
.getVerbose(), ifLevel
=
2
, indent
=
self
.getIndent(), logFile
=
self
.getLogFile())