创建和启动 FlashCopy 映射的代码样本
该信息演示 CIMOM 方法如何控制集群系统。样本代码包含来自 Java™ 类且用于创建和启动 FlashCopy® 映射的主方法以及从该主方法中调用的其他方法。
在本主题中,术语方法 (method) 指 Java 方法。术语方法 (Method,首字母大写) 指 CIM 方法。
Java 主方法
本示例显示用于创建和启动 FlashCopy 映射的 Java 主方法。 本示例中假定 Java 程序每次都用于控制相同的集群系统。使其变为更加灵活是一个相对简单的过程,但具体决定由用户来完成。
/*
* FC Mapping states
*/
private static UnsignedInt16 INITIALIZED = new UnsignedInt16(2);
private static UnsignedInt16 PREPARING = new UnsignedInt16(3);
private static UnsignedInt16 PREPARED = new UnsignedInt16(4);
public static void main(String[] args) throws CIMException
{
/*
* First step is to connect to the CIMOM
*/
UserPrincipal user = new UserPrincipal("superuser");
PasswordCredential pwd = new PasswordCredential("itso13sj");
CIMNameSpace ns = new CIMNameSpace("https://9.43.86.115:5989/root/ibm");
CIMClient client = null;
client = new CIMClient(ns,user,pwd);
/*
* Next, select the clustered system that we are interested in
*/
CIMInstance chosenCluster = getCluster("ITSOCL1",client);
/*
* At this point, the relevant clustered system has been selected
* and 'chosenCluster' is a CIMInstance of this clustered system
*
* Get the Config Service of this clustered system
*/
CIMObjectPath cService = getConfigService(chosenCluster, client);
/*
* Now, get all of the Volumes in this clustered system
*/
Map<Integer,CIMObjectPath> volumesById = getVolumes(chosenCluster,client);
/*
* Select the FlashCopy Source
*
* In this case, Volume 10 is our source
* Volume 11 is our target
*/
CIMObjectPath fcSrc = volumesById.get(new Integer(10));
CIMObjectPath fcTgt = volumesById.get(new Integer(11));/*
/*
* Now create FC Mapping
*/
CIMValue rc = makeFlashCopyMapping("CIMOMTestMap", fcSrc, fcTgt, cService,
client,false);
/*
* Now that this has been created, we need to get an
* Object Path to the newly created Association
*/
List<CIMObjectPath> fcMaps = getFCMappings(fcSrc, client);
CIMObjectPath fcMapping = fcMaps.get(0);
/*
* Now we prepare the FC Mapping
*/
CIMArgument[] outArgs = new CIMArgument[2];
rc = prepareFCMapping(cService, fcMapping, client, outArgs);
System.out.println("Got value:"+
Integer.toHexString(Integer.parseInt(rc.toString())));
/*
* Loop until it is prepared
*/
CIMValue fcMapState = new CIMValue(PREPARING);
while(fcMapState.equals(new CIMValue(PREPARING)))
{
CIMInstance fcMapInfo = client.getInstance(fcMapping);
fcMapState = fcMapInfo.getProperty("SyncState").getValue();
}
/*
* Now start the FC Mapping
*/
rc = startFCMapping(cService, fcMapping, client, outArgs);
System.out.println("Got value:"+
Integer.toHexString(Integer.parseInt(rc.toString())));
}
getCluster 方法
getCluster 方法返回与具有所提供名称的集群系统对应的 CIM 实例。它通过枚举类 IBMTSSVC_Cluster 的所有实例并检查每个实例的名称来完成该操作。 当找到与所提供名称匹配的实例时,将返回到该实例的对象路径。
static private CIMInstance getCluster(String clusterName, CIMClient client) throws
CIMException
{
CIMInstance chosenCluster = null;
Enumeration<CIMInstance> clusters =
client.enumerateInstances(new CIMObjectPath("/root/ibm:IBMTSSVC_Cluster"));
while(clusters.hasMoreElements())
{
CIMInstance possibleCluster = clusters.nextElement();
String possibleName =
possibleCluster.getProperty("ElementName").getValue().toString();
if(possibleName.equals("\""+clusterName+"\""))
{
chosenCluster = possibleCluster;
}
}
return chosenCluster;
}
getConfigService 方法
CIM_StorageConfigurationService 类在 Storwize® V3500 中没有直接对等项,但针对该系统调用方法时需要该类的一个实例。
在该方法中,将请求与所提供的集群系统关联的所有实例。将集群系统与其配置服务连接起来的关联是 CIM_HostedService。由于集群系统只具有与其关联的配置服务,因此选择了枚举中的第一个对象路径。
static private CIMObjectPath getConfigService(CIMInstance cluster, CIMClient
client) throws CIMException
{
Enumeration<CIMObjectPath> configServices = null;
configServices = client.associatorNames(
cluster.getObjectPath(),
"CIM_HostedService",
"CIM_StorageConfigurationService",
null,
null);
return configServices.nextElement();
}
getVolumes 方法
该方法返回将卷标识(整数)与 IBMTSSVC_StorageVolume 对象路径关联的映射。该方法请求与所提供的 clustered system 实例关联的所有 IBMTSSVC_StorageVolume 实例。
static private Map<Integer,CIMObjectPath> getVolumes(CIMInstance cluster, CIMClient
client) throws CIMException
{
Enumeration<CIMObjectPath> volumes = client.associatorNames(
cluster.getObjectPath(),
null,
"IBMTSSVC_StorageVolume",
null,
null);
Map<Integer,CIMObjectPath> volumesById = new HashMap<Integer, CIMObjectPath>();
while(volumes.hasMoreElements())
{
CIMObjectPath volumeOP = volumes.nextElement();
CIMValue volumesId = volumeOP.getKey("DeviceID").getValue();
String idAsString = volumeId.toString();
String idNoQuotes = idAsString.substring(1, idAsString.length()-1);
volumesById.put(Integer.parseInt(idNoQuotes), volumeOP);
}
return volumesById;
}
makeFlashCopyMapping 方法
本示例针对集群系统配置服务调用 AttachReplica。CIM 方法接受类型化参数;该方法使用 argRef、 argString 和 argUint16 方法。这些方法充当生成 CIM 方法所需自变量的快捷方式。 AttachReplica 方法用于 FlashCopy。CopyType 自变量指示所需的类型。
static private CIMValue makeFlashCopyMapping(
String name,
CIMObjectPath source,
CIMObjectPath target,
CIMObjectPath configService,
CIMClient client,
boolean autodelete) throws CIMException
{
CIMArgument src = argRef("SourceElement", source, "IBMTSSVC_StorageVolume");
CIMArgument tgt = argRef("TargetElement", target, "IBMTSSVC_StorageVolume");
CIMArgument fcName = argString("ElementName",name);
CIMArgument type = argUint16("CopyType",autodelete?5:4);
CIMArgument[] inArgs = {src,tgt,fcName,type};
CIMArgument[] outArgs = new CIMArgument[1];
CIMValue rc = client.invokeMethod(configService,
"AttachReplica",
inArgs,
outArgs);
return rc;
}
getFCMappings 方法
getFCMappings 方法返回与所提供卷关联的所有 FCMapping 的列表。本方法请求引用所提供 IBMTSSVC_StorageVolume 的所有关联的列表。 目前,该类型的所有 Java WBEM 服务方法都返回枚举;该方法会将此转换为列表以易于使用。
static private List<CIMObjectPath> getFCMappings(CIMObjectPath volume, CIMClient
client) throws CIMException
{
Enumeration<CIMObjectPath> assocs = client.referenceNames(
volume,
"IBMTSSVC_LocalStorageSynchronized",
null);
return Collections.list(assocs);
}
prepareFCMapping 方法
prepareFCMapping 方法准备 FlashCopy 映射。 与 AttachReplica 方法非常相似,ModifySynchronization 方法用于控制 FlashCopy。operation 参数指示您实际要执行的操作。
private static CIMValue prepareFCMapping(
CIMObjectPath configService,
CIMObjectPath fcMapping,
CIMClient client,
CIMArgument[] outArgs) throws CIMException
{
CIMArgument operation = argUint16("Operation", 6);
CIMArgument synch = argRef("Synchronization",
fcMapping,"IBMTSSVC_FlashCopyStorageSynchronized");
CIMArgument[] inArgs = new CIMArgument[]{operation,synch};
outArgs = new CIMArgument[2];
return client.invokeMethod(configService,
"ModifySynchronization",
inArgs,
outArgs);
startFCMapping 方法
startFCMapping 方法启动 FlashCopy 映射。 该方法与在prepareFCMapping 方法中一样调用 ModifySynchronization 方法,但使用不同的 operation 参数。
private static CIMValue startFCMapping(
CIMObjectPath configService,
CIMObjectPath fcMapping,
CIMClient client,
CIMArgument[] outArgs) throws CIMException
{
CIMArgument operation = argUint16("Operation", 4);
CIMArgument synch = argRef("Synchronization",
fcMapping,"IBMTSSVC_FlashCopyStorageSynchronized");
CIMArgument[] inArgs = new CIMArgument[]{operation,synch};
outArgs = new CIMArgument[2];
return client.invokeMethod(configService,
"ModifySynchronization",
inArgs,
outArgs);
}
自变量生成器类
该类使用以下自变量生成器:
- argUint16 方法返回一个无符号的 16 位整数类型的自变量。
static private CIMArgument argUint16(String name, int arg) { return new CIMArgument( name, new CIMValue( new UnsignedInt16(arg), new CIMDataType(CIMDataType.UINT16) ) ); }
- argString 方法返回一个字符串类型的自变量。
static private CIMArgument argString(String name, String str ) { return new CIMArgument( name, new CIMValue( str, new CIMDataType(CIMDataType.STRING) ) ); }
- argRef 方法返回一个引用类型的自变量。它是对提供的对象路径指示的实例的引用。
static private CIMArgument argRef( String name, CIMObjectPath path, String className ) { return new CIMArgument( name, new CIMValue( path, new CIMDataType(className) ) ); }