Search in sources :

Example 1 with ResignatureAnswer

use of org.apache.cloudstack.storage.command.ResignatureAnswer 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)

Example 2 with ResignatureAnswer

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

the class XenServerStorageProcessor method resignature.

@Override
public ResignatureAnswer resignature(final ResignatureCommand cmd) {
    SR newSr = null;
    final Connection conn = hypervisorResource.getConnection();
    try {
        final Map<String, String> details = cmd.getDetails();
        final String iScsiName = details.get(DiskTO.IQN);
        final String storageHost = details.get(DiskTO.STORAGE_HOST);
        final String chapInitiatorUsername = details.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String chapInitiatorSecret = details.get(DiskTO.CHAP_INITIATOR_SECRET);
        newSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, true, false);
        Set<VDI> vdis = newSr.getVDIs(conn);
        if (vdis.size() != 1) {
            throw new RuntimeException("There were " + vdis.size() + " VDIs in the SR.");
        }
        VDI vdi = vdis.iterator().next();
        final ResignatureAnswer resignatureAnswer = new ResignatureAnswer();
        resignatureAnswer.setSize(vdi.getVirtualSize(conn));
        resignatureAnswer.setPath(vdi.getUuid(conn));
        resignatureAnswer.setFormat(ImageFormat.VHD);
        return resignatureAnswer;
    } catch (final Exception ex) {
        s_logger.warn("Failed to resignature: " + ex.toString(), ex);
        return new ResignatureAnswer(ex.getMessage());
    } finally {
        if (newSr != null) {
            hypervisorResource.removeSR(conn, newSr);
        }
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) VDI(com.xensource.xenapi.VDI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ResignatureAnswer (org.apache.cloudstack.storage.command.ResignatureAnswer)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 Connection (com.xensource.xenapi.Connection)1 SR (com.xensource.xenapi.SR)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VDI (com.xensource.xenapi.VDI)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)1 ResignatureCommand (org.apache.cloudstack.storage.command.ResignatureCommand)1 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1