2013-04-16 20 views
3

我试着在WLST试图让一个集群的名称WLST

cd("/JDBCSystemResources/<datasource name>") 
targets = get('Targets') 
mytarget = targets[0] 

这工作得很好,以获得数据源的第一个簇的字符串值名称。如果我使用viewMBean命令“viewMBean(mytarget)”,我可以看到Name为属性“Name”

如果我打印mytarget的值,我会得到类似于:“com.bea:Name = Cluster-1,Type =集群”

但我不能工作,如何获取名称(‘集群1’在上面的例子)

目前,我想不出什么做除了让群集名称作为对象的字符串表示的子串,这听起来不像是要做的事情

任何帮助表示赞赏。

更新:

由于没有答案为止我使用这个解决方案,但仍然希望一个更好的

# get the target cluster from the string "com.bea:Name=<clustername>,Type=Cluster" 
if len(targets) == 1 : 
    tstring = str(targets[0]) 
    targetCluster = tstring[13:tstring.find(",Type=Cluster")] 
    print "targetCluster = "+targetCluster; 
else : 
    raise Exception("Expected single target cluster for datasource. Targets length was "+str(len(targets))) 

回答

2

你可以只说targets[0].getName()为我工作:)

+0

比从未更好的迟到;-) – Dunderklumpen

1

的代码的问题似乎是我们的最佳答案。即将群集转换为一个字符串,然后获取群集名称的子字符串。

相关问题