Código de amostra para criar e iniciar um mapeamento do FlashCopy
Essa informação demonstra como os métodos de CIMOM controlam o sistema em cluster. O código de amostra inclui um método main de uma classe do Java™ projetada para criar e iniciar um mapeamento do FlashCopy e outros métodos chamados do método main.
Neste tópico, o termo método se refere a um método Java. O termo Método (inicial maiúscula) se refere a um Método CIM.
método main Java
Esse exemplo mostra o método main Java para criar e iniciar um mapeamento do FlashCopy. A suposição nesse exemplo é que o programa Java é projetado para controlar o mesmo sistema em cluster todas as vezes. É um processo relativamente simples para torná-lo mais flexível, mas essa decisão é deixada para o usuário.
/*
* 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())));
}
método getCluster
O método getCluster retorna a instância CIM correspondentes ao sistema em cluster com o nome fornecido. Ele faz isso, enumerando todas as instâncias do IBMTSSVC_Cluster de classe e, em seguida, verificando o nome de cada instância. Quando uma instância que corresponde ao nome fornecido for localizada, será retornado um caminho de objeto para essa instância.
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;
}
método getConfigService
A classe CIM_StorageConfigurationService não tem um equivalente direto em um Storwize V3700, mas uma instância dessa classe é necessária para chamar métodos com relação ao sistema.
Nesse método, todas as instâncias associadas com osistema em cluster fornecido são solicitadas. A associação se conectando a um sistema em cluster para sua configuração de serviço é CIM_HostedService. Porque um sistema em cluster possui apenas o serviço de configuração associado a ele, o primeiro caminho do objeto na enumeração é selecionado.
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();
}
método getvolumes
Este método retorna um mapa relacionado aos IDs do Volume (como números inteiros) para os caminhos de objeto do IBMTSSVC_StorageVolume. O método solicita todas as instâncias do IBMTSSVC_StorageVolume associadas à instância do sistema em cluster.
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;
}
método makeFlashCopyMapping
Este exemplo chama o AttachReplica com relação ao serviço de configuração do sistema em cluster. Os Métodos CIM aceitam os parâmetros digitados; esse método faz uso dos métodos argRef, argString e argUint16. Esses métodos agem como atalhos para gerar os argumentos necessários para o Método CIM. O método AttachReplica é usado para o FlashCopy. O argumento CopyType indica qual tipo será necessário.
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;
}
método getFCMappings
O método getFCMappings retorna uma lista de todos os FCMappings associados ao volume fornecido. Esse método solicita uma lista de todas as associações que fazem referência ao IBMTSSVC_StorageVolume fornecido. Atualmente, todos os métodos WBEM Services Java desse tipo retornam enumerações; esse método converte isso para uma lista para facilitar o uso.
static private List<CIMObjectPath> getFCMappings(CIMObjectPath volume, CIMClient
client) throws CIMException
{
Enumeration<CIMObjectPath> assocs = client.referenceNames(
volume,
"IBMTSSVC_LocalStorageSynchronized",
null);
return Collections.list(assocs);
}
método prepareFCMapping
O método prepareFCMapping prepara um mapeamento do FlashCopy. Muito parecido com o Método AttachReplica, o Método ModifySynchronization controla o FlashCopy. O parâmetro operation indica o que realmente deve ser feito.
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);
método startFCMapping
O método startFCMapping inicia um mapeamento do FlashCopy. Esse método chama o Método ModifySynchronization como em método prepareFCMapping, mas usa um parâmetro operation diferente.
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);
}
Classe de geradores de argumentos
Essa classe usa os geradores de argumentos a seguir:
- O método argUint16 retorna um argumento digitado
um número inteiro de 16 bits não assinado.
static private CIMArgument argUint16(String name, int arg) { return new CIMArgument( name, new CIMValue( new UnsignedInt16(arg), new CIMDataType(CIMDataType.UINT16) ) ); }
- O método argString retorna um argumento digitado por uma
sequência de caracteres.
static private CIMArgument argString(String name, String str ) { return new CIMArgument( name, new CIMValue( str, new CIMDataType(CIMDataType.STRING) ) ); }
- O método argRef retorna um argumento digitado de
referência. É uma referência à instância a que o caminho de objeto
fornecido indica.
static private CIMArgument argRef( String name, CIMObjectPath path, String className ) { return new CIMArgument( name, new CIMValue( path, new CIMDataType(className) ) ); }