FlashCopy 맵핑을 작성 및 시작할 샘플 코드

이 정보는 CIMOM 메소드가 시스템을 제어하는 방법을 설명합니다. 샘플 코드에는 FlashCopy® 맵핑을 작성하고 시작하도록 설계된 Java™ 클래스의 기본 메소드와 기본 메소드에서 호출되는 기타 메소드가 포함됩니다.

이 주제에서 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 클래스는 시스템에 직접적인 동등 항목이 없지만, 시스템에 대해 메소드를 호출하는 데 이 클래스의 인스턴스가 필요합니다.

이 메소드에서는 제공된 시스템과 연관된 모든 인스턴스가 요청됩니다. 시스템을 구성 서비스에 연결하는 연관은 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 메소드

이 메소드는 볼륨 ID(정수)를 IBMTSSVC_StorageVolume 오브젝트 경로에 관련시키는 맵을 리턴합니다. 이 메소드는 제공된 클러스터형 시스템 인스턴스와 연관된 모든 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, argStringargUint16 메소드를 사용합니다. 이들 메소드는 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)
                   )
             );
    }