Search in sources :

Example 1 with ModifyStoragePoolAnswer

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());
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) FenceAnswer(com.cloud.agent.api.FenceAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) OvmStoragePool(com.cloud.ovm.object.OvmStoragePool) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with ModifyStoragePoolAnswer

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);
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) DatastoreSummary(com.vmware.vim25.DatastoreSummary) RemoteException(java.rmi.RemoteException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with ModifyStoragePoolAnswer

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());
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Answer(com.cloud.agent.api.Answer) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) StorageDetails(com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 4 with ModifyStoragePoolAnswer

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);
        }
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 5 with ModifyStoragePoolAnswer

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;
}
Also used : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.exception.StorageConflictException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Aggregations

ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)16 Answer (com.cloud.agent.api.Answer)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)8 TemplateProp (com.cloud.storage.template.TemplateProp)7 HashMap (java.util.HashMap)6 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)5 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)5 ConfigurationException (javax.naming.ConfigurationException)5 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)4 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)4 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)4 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)4 RebootAnswer (com.cloud.agent.api.RebootAnswer)4 StartAnswer (com.cloud.agent.api.StartAnswer)4 StopAnswer (com.cloud.agent.api.StopAnswer)4 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)4 TemplateInfo (com.cloud.storage.template.TemplateInfo)4 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)3 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)3