Search in sources :

Example 1 with ResignatureCommand

use of org.apache.cloudstack.storage.command.ResignatureCommand in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method performResignature.

private CopyCmdAnswer performResignature(DataObject dataObj, HostVO hostVO, boolean keepGrantedAccess) {
    long storagePoolId = dataObj.getDataStore().getId();
    DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    Map<String, String> details = getDetails(dataObj);
    ResignatureCommand command = new ResignatureCommand(details);
    ResignatureAnswer answer = null;
    try {
        _volumeService.grantAccess(dataObj, hostVO, dataStore);
        answer = (ResignatureAnswer) _agentMgr.send(hostVO.getId(), command);
    } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) {
        keepGrantedAccess = false;
        String msg = "Failed to resign the DataObject with the following ID: " + dataObj.getId();
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage());
    } finally {
        if (keepGrantedAccess == false) {
            _volumeService.revokeAccess(dataObj, hostVO, dataStore);
        }
    }
    if (answer == null || !answer.getResult()) {
        final String errMsg;
        if (answer != null && answer.getDetails() != null && !answer.getDetails().isEmpty()) {
            errMsg = answer.getDetails();
        } else {
            errMsg = "Unable to perform resignature operation in 'StorageSystemDataMotionStrategy.performResignature'";
        }
        throw new CloudRuntimeException(errMsg);
    }
    VolumeObjectTO newVolume = new VolumeObjectTO();
    newVolume.setSize(answer.getSize());
    newVolume.setPath(answer.getPath());
    newVolume.setFormat(answer.getFormat());
    return new CopyCmdAnswer(newVolume);
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) ResignatureCommand(org.apache.cloudstack.storage.command.ResignatureCommand) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)1 ResignatureAnswer (org.apache.cloudstack.storage.command.ResignatureAnswer)1 ResignatureCommand (org.apache.cloudstack.storage.command.ResignatureCommand)1 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)1