Search in sources :

Example 1 with ModifyStoragePoolAnswer

use of com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer in project cosmic by MissionCriticalCloud.

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(final long hostId, final long poolId) throws StorageConflictException {
    final StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        final String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    final ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        final String datastoreName = mspAnswer.getLocalDatastoreName();
        final List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (final StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(poolHost);
    } else {
        poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    }
    final StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
    poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
    primaryStoreDao.update(pool.getId(), poolVO);
    s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
    return true;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) StoragePool(com.cloud.legacymodel.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.legacymodel.exceptions.StorageConflictException) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand)

Example 2 with ModifyStoragePoolAnswer

use of com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtModifyStoragePoolCommandWrapper method execute.

@Override
public Answer execute(final ModifyStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    final KvmStoragePool storagepool = storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
    if (storagepool == null) {
        return new Answer(command, false, " Failed to create storage pool");
    }
    final Map<String, TemplateProp> tInfo = new HashMap<>();
    final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, storagepool.getCapacity(), storagepool.getAvailable(), tInfo);
    return answer;
}
Also used : TemplateProp(com.cloud.legacymodel.storage.TemplateProp) Answer(com.cloud.legacymodel.communication.answer.Answer) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)

Example 3 with ModifyStoragePoolAnswer

use of com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer in project cosmic by MissionCriticalCloud.

the class CitrixModifyStoragePoolCommandWrapper method execute.

@Override
public Answer execute(final ModifyStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final StorageFilerTO pool = command.getPool();
    final boolean add = command.getAdd();
    if (add) {
        try {
            final SR sr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
            citrixResourceBase.setupHeartbeatSr(conn, sr, false);
            final long capacity = sr.getPhysicalSize(conn);
            final long available = capacity - sr.getPhysicalUtilisation(conn);
            if (capacity == -1) {
                final String msg = "Pool capacity is -1! pool: " + pool.getHost() + pool.getPath();
                s_logger.warn(msg);
                return new Answer(command, false, msg);
            }
            final Map<String, TemplateProp> tInfo = new HashMap<>();
            final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, capacity, available, tInfo);
            return answer;
        } catch (final XenAPIException e) {
            final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        } catch (final Exception e) {
            final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        }
    } else {
        try {
            final SR sr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
            final String srUuid = sr.getUuid(conn);
            final String result = citrixResourceBase.callHostPluginPremium(conn, "setup_heartbeat_file", "host", citrixResourceBase.getHost().getUuid(), "sr", srUuid, "add", "false");
            if (result == null || !result.split("#")[1].equals("0")) {
                throw new CloudRuntimeException("Unable to remove heartbeat file entry for SR " + srUuid + " due to " + result);
            }
            return new Answer(command, true, "seccuss");
        } catch (final XenAPIException e) {
            final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        } catch (final Exception e) {
            final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        }
    }
}
Also used : TemplateProp(com.cloud.legacymodel.storage.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Answer(com.cloud.legacymodel.communication.answer.Answer) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)3 ModifyStoragePoolAnswer (com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer)3 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)2 TemplateProp (com.cloud.legacymodel.storage.TemplateProp)2 HashMap (java.util.HashMap)2 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)1 ModifyStoragePoolCommand (com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand)1 StorageConflictException (com.cloud.legacymodel.exceptions.StorageConflictException)1 StoragePool (com.cloud.legacymodel.storage.StoragePool)1 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)1 Connection (com.xensource.xenapi.Connection)1 SR (com.xensource.xenapi.SR)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1