[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-9280?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15582347#comment-15582347
 ] 

ASF GitHub Bot commented on CLOUDSTACK-9280:
--------------------------------------------

Github user GabrielBrascher commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1559#discussion_r83628876
  
    --- Diff: 
engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java
 ---
    @@ -77,22 +80,51 @@ public VolumeInfo getVolume(long volumeId, 
DataStoreRole storeRole) {
     
         @Override
         public VolumeInfo getVolume(long volumeId) {
    +        return getVolume(volumeId, false);
    +    }
    +
    +    @Override
    +    public VolumeInfo getVolumeForExpunge(long volumeId) {
    +        return getVolume(volumeId, true);
    +    }
    +
    +    protected VolumeInfo getVolume(long volumeId, boolean forExpunge) {
             VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
             if (volumeVO == null) {
                 return null;
             }
    +
    +        String dataStoreRole = "";
             VolumeObject vol = null;
             if (volumeVO.getPoolId() == null) {
    +            dataStoreRole = DataStoreRole.Image.toString();
                 DataStore store = null;
                 VolumeDataStoreVO volumeStore = 
volumeStoreDao.findByVolume(volumeId);
                 if (volumeStore != null) {
    -                store = 
storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
    +                if (forExpunge) {
    +                    store = 
storeMgr.getDataStoreForExpunge(volumeStore.getDataStoreId(), 
DataStoreRole.Image);
    +                } else {
    +                    store = 
storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
    +                }
                 }
    +
                 vol = VolumeObject.getVolumeObject(store, volumeVO);
             } else {
    -            DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), 
DataStoreRole.Primary);
    +            DataStore store = null;
    +            dataStoreRole = DataStoreRole.Primary.toString();
    +            if (forExpunge) {
    +                store = 
storeMgr.getDataStoreForExpunge(volumeVO.getPoolId(), DataStoreRole.Primary);
    +            } else {
    +                store = storeMgr.getDataStore(volumeVO.getPoolId(), 
DataStoreRole.Primary);
    +            }
    +
                 vol = VolumeObject.getVolumeObject(store, volumeVO);
             }
    +
    +        if (vol.getDataStore() == null && forExpunge) {
    +            logger.warn("Was unable to find a DataStore (role = " + 
dataStoreRole + ") for expunged volume " + volumeId);
    --- End diff --
    
    Just a tip here. The [String 
format](https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html) can 
be very handy in cases like this.


> System VM volumes cannot be deleted when there are no system VMs
> ----------------------------------------------------------------
>
>                 Key: CLOUDSTACK-9280
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9280
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: Management Server
>    Affects Versions: 4.6.0, 4.7.0
>            Reporter: Jeff Hair
>
> Scenario: When deleting a zone, everything under it must be removed. This 
> results in the system VMs being destroyed as there are no more hosts running.
> The storage cleanup thread properly detects that there are volumes to be 
> deleted, but it cannot delete them because the endpoint selection fails with 
> "No remote endpoint to send DeleteCommand, check if host or ssvm is down?"



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to