use of com.cloud.agent.api.ModifyStoragePoolAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
protected Answer execute(ModifyStoragePoolCommand cmd) {
StorageFilerTO pool = cmd.getPool();
try {
if (pool.getType() == StoragePoolType.NetworkFilesystem) {
createNfsSr(pool);
} else if (pool.getType() == StoragePoolType.OCFS2) {
createOCFS2Sr(pool);
} else {
return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
}
setupHeartBeat(pool.getUuid());
OvmStoragePool.Details d = OvmStoragePool.getDetailsByUuid(_conn, pool.getUuid());
Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, d.totalSpace, d.freeSpace, tInfo);
return answer;
} catch (Exception e) {
s_logger.debug("ModifyStoragePoolCommand failed", e);
return new Answer(cmd, false, e.getMessage());
}
}
use of com.cloud.agent.api.ModifyStoragePoolAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(ModifyStoragePoolCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource ModifyStoragePoolCommand: " + _gson.toJson(cmd));
}
try {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
StorageFilerTO pool = cmd.getPool();
if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS) {
throw new Exception("Unsupported storage pool type " + pool.getType());
}
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
if (morDatastore == null) {
morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""));
}
assert (morDatastore != null);
DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary();
long capacity = summary.getCapacity();
long available = summary.getFreeSpace();
Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
if (cmd.getAdd() && pool.getType() == StoragePoolType.VMFS) {
answer.setLocalDatastoreName(morDatastore.getValue());
}
return answer;
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
}
}
use of com.cloud.agent.api.ModifyStoragePoolAnswer in project cloudstack by apache.
the class Ovm3StoragePool method execute.
/**
* Gets the details of a storage pool, size etc
*
* @param cmd
* @return
*/
public Answer execute(ModifyStoragePoolCommand cmd) {
StorageFilerTO pool = cmd.getPool();
LOGGER.debug("modifying pool " + pool);
try {
if (config.getAgentInOvm3Cluster()) {
// no native ovm cluster for now, I got to break it in horrible
// ways
}
if (pool.getType() == StoragePoolType.NetworkFilesystem) {
createRepo(pool);
StoragePlugin store = new StoragePlugin(c);
String propUuid = store.deDash(pool.getUuid());
String mntUuid = pool.getUuid();
String nfsHost = pool.getHost();
String nfsPath = pool.getPath();
StorageDetails ss = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, nfsHost, nfsPath);
Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
return new ModifyStoragePoolAnswer(cmd, Long.parseLong(ss.getSize()), Long.parseLong(ss.getFreeSize()), tInfo);
} else if (pool.getType() == StoragePoolType.OCFS2) {
createOCFS2Sr(pool);
}
return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
} catch (Exception e) {
LOGGER.debug("ModifyStoragePoolCommand failed", e);
return new Answer(cmd, false, e.getMessage());
}
}
use of com.cloud.agent.api.ModifyStoragePoolAnswer in project cloudstack by apache.
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 String srName = command.getStoragePath() != null ? command.getStoragePath() : pool.getUuid();
final SR sr = citrixResourceBase.getStorageRepository(conn, srName);
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<String, TemplateProp>();
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, "success");
} 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);
}
}
}
use of com.cloud.agent.api.ModifyStoragePoolAnswer in project cloudstack by apache.
the class DefaultHostListener method hostConnect.
@Override
public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
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()) {
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;
ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
String datastoreName = mspAnswer.getLocalDatastoreName();
List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
for (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("//", "/"));
}
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;
}
Aggregations