コード例 #1
0
 private void createTargetSnapshot(
     String snapshotId, OpenstackFileCloneVolumeStatus status, String operationId)
     throws CloudClientException {
   String[] keys = {OpenstackConstants.TARGET_VOLUME_TAG, OpenstackConstants.CLONE_OPERATION_TAG};
   String[] values = new String[2];
   values[1] = operationId;
   String targetRegion =
       status.volumeToBeCloned.targetStorageSystemId.substring(
           status.volumeToBeCloned.targetStorageSystemId.indexOf(':') + 1);
   ShareSnapshot snapshot =
       openstackClient.copy(
           snapshotId,
           targetRegion,
           "LVM Snapshot to clone Volume " + status.volumeToBeCloned.sourceVolumeId);
   // is this used??
   status.targetSnapshotId = targetRegion + ':' + snapshot.getId();
 }
コード例 #2
0
  @Override
  public StorageOperationResponse<CloneVolumesResponse> cloneVolumes(CloneVolumesRequest request) {

    String msg = "";
    PrepareCloneVolumesRequest prepareRequest =
        (PrepareCloneVolumesRequest) request.prepareCloneVolumesResult;
    List<VolumeToBeCloned> volumesToBeCloned = prepareRequest.volumesToBeCloned;
    ArrayList<StorageLogMessage> logMessages = new ArrayList<StorageLogMessage>();

    logger.log(
        IJavaEeLog.SEVERITY_DEBUG,
        this.getClass().getName(),
        "cloneVolumes: request:" + prepareRequest,
        null);
    msg = "CloneVolumes operation started";
    logMessages.add(
        new StorageLogMessage(IJavaEeLog.SEVERITY_INFO, "OSFile", System.currentTimeMillis(), msg));
    String operationId = OpenstackAdapterUtil.generateOperationId();
    ArrayList<String> snapshots = new ArrayList<String>();

    OpenstackFileCloneVolumesContext context = new OpenstackFileCloneVolumesContext();
    context.volumeStatus = new ArrayList<OpenstackFileCloneVolumeStatus>();
    OpenstackFileCloneVolumeStatus status;
    for (VolumeToBeCloned inputVolume : volumesToBeCloned) {
      status = new OpenstackFileCloneVolumeStatus();
      status.volumeToBeCloned = inputVolume;
      status.customCloningProperties = prepareRequest.customCloningProperties;
      context.volumeStatus.add(status);
      try {
        if (inputVolume.isSourceVolumeSnapshot) {
          if (openstackClient.getSnapshot(inputVolume.sourceVolumeId) != null) {
            status.sourceSnapshotComplete = true;
            status.sourceSnapshotId = inputVolume.sourceVolumeId;
            if (isRemoteClone(status.volumeToBeCloned)) {
              createTargetSnapshot(status.sourceSnapshotId, status, operationId);
              snapshots.add(status.targetSnapshotId);
              msg = "Target snapshot" + status.targetSnapshotId + " created";
              logMessages.add(
                  new StorageLogMessage(
                      IJavaEeLog.SEVERITY_INFO, "LVM", System.currentTimeMillis(), msg));
            }

          } else {
            msg = "Snapshot not found: " + inputVolume.sourceVolumeId;
            logMessages.add(
                new StorageLogMessage(
                    IJavaEeLog.SEVERITY_ERROR, "OSFile", System.currentTimeMillis(), msg));
            return StorageAdapterImplHelper.createFailedResponse(
                logMessages, CloneVolumesResponse.class);
          }
        } else {
          ShareSnapshot snapshot = null;
          try {
            String snapshotName = "Snapshot of share " + inputVolume.sourceVolumeId;
            String snapshotDescription =
                "LVM Snapshot to clone share " + inputVolume.sourceVolumeId;
            snapshot =
                openstackClient.createShareSnapshot(
                    inputVolume.sourceVolumeId, snapshotName, snapshotDescription);
          } catch (CloudClientException e) {

            throw e;
          }
          snapshots.add(snapshot.getId());
          status.sourceSnapshotId = snapshot.getId();
        }
      } catch (CloudClientException e) {
        logger.traceThrowable(
            IJavaEeLog.SEVERITY_DEBUG,
            this.getClass().getName(),
            "cloneVolumes:" + e.getMessage(),
            null,
            e);
        logMessages.add(
            0,
            new StorageLogMessage(
                IJavaEeLog.SEVERITY_ERROR, "OSFile", System.currentTimeMillis(), e.getMessage()));
        return StorageAdapterImplHelper.createFailedResponse(
            logMessages, CloneVolumesResponse.class);
      }
    }
    msg = "CloneVolumes operation ended";
    logMessages.add(
        new StorageLogMessage(IJavaEeLog.SEVERITY_INFO, "OSFile", System.currentTimeMillis(), msg));

    CloneVolumesResponse payload = new CloneVolumesResponse();
    context.operationId = operationId;
    context.customCloningProperties = prepareRequest.customCloningProperties;
    payload.cloneVolumeResult = context;
    StorageOperationResponse<CloneVolumesResponse> response =
        new StorageOperationResponse<CloneVolumesResponse>(payload);
    response.setLogMessages(logMessages);
    response.setPercentCompleted(100);
    response.setStatus(StorageOperationStatus.COMPLETED);
    response.setContext(context);
    return response;
  }